Skip to content

Instantly share code, notes, and snippets.

import UIKit
class ViewController: UIViewController, ViewControllerThatCanBlowUp {
override func viewDidLoad() {
super.viewDidLoad()
var viewControllersThatAreUnderSuspicionForBeingBlowUpable: [ViewControllerThatCanBlowUp] = []
// Was seen buying a lot of fireworks
let vc1 = ViewController()
@christianselig
christianselig / milkshake.swift
Last active March 20, 2021 11:37
A beautiful milkshake where the ingredients are Sean Heber, Yakov Shapovalov, and Hunter Meyer.
/// 🥤
extension Dictionary where Key: RawRepresentable {
func rawConversion<NewKey>() -> Dictionary<NewKey, Value> where NewKey == Key.RawValue {
let newDict: [NewKey: Value] = self.reduce(into: [:]) { (result, item) in
result[item.key.rawValue] = item.value
}
return newDict
}
}
@christianselig
christianselig / zombie-banana.swift
Created March 20, 2021 20:12
Zombie banana uprising
class Banana: NSObject, NSSecureCoding {
let bananaName: String
let userInfo: [String: Any]
static var supportsSecureCoding: Bool = true
init(bananaName: String, userInfo: [String: Any]) {
self.bananaName = bananaName
self.userInfo = userInfo
}
@christianselig
christianselig / context-menu.swift
Created May 6, 2021 01:41
Attempt at organizing my context menu code better
import UIKit
class ViewController: UIViewController {
var contextMenuDataSource = CommentsContextMenuHandler()
override func viewDidLoad() {
super.viewDidLoad()
let interaction = UIContextMenuInteraction(delegate: contextMenuDataSource)
view.addInteraction(interaction)
import SwiftUI
struct Setting {
enum SettingIcon {
case system(name: String)
case custom(name: String)
}
enum SettingType: Equatable {
case toggle
struct Setting {
enum SettingIcon {
case system(name: String)
case custom(name: String)
}
enum SettingType: Equatable {
case toggle
case menu(settings: [MenuSetting])
case viewController(creationBlock: (() -> UIViewController))
//
// ContentView.swift
// TestSwiftSettings3
//
// Created by Christian Selig on 2021-05-13.
//
import SwiftUI
import Combine
import UIKit
import AVKit
class ViewController: UIViewController {
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
let videoURL = URL(string: "https://v.redd.it/dneaulg46lt61/HLSPlaylist.m3u8?a=1624119730%2CZjViMWYxNmQ3MjM2MWNhNjE1NTIyNGNiNDA5NDQ2Njk2ZjNhNmRmNmJiYmEwNzZkMTdmYjJkNmNkNzE2MTE0Yg%3D%3D&v=1&f=sd")!
let player = AVPlayer(url: videoURL)
let playerViewController = AVPlayerViewController()
override func viewDidLoad() {
super.viewDidLoad()
let url = URL(string: "https://external-preview.redd.it/nL7zG2Q2FkHwyJ15KgT4A7jk2R4cMddQpKb_Kx9YR8U.jpg?width=1080&crop=smart&auto=webp&s=91ee8327fdb33b3bb94cb0eab7e26221763e33f4")!
URLSession.shared.dataTask(with: url) { data, response, error in
print("Downloaded! Waiting…")
DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(8)) {
// Immediately spikes approximately 7 MB upon execution
@christianselig
christianselig / UIAlertController+Conversion.swift
Created September 3, 2021 18:14
Adding an image to a UIAlertController
extension UIAlertController {
/// Creates a view controller for notifying the user that a conversion is occurring. Accepts a block that is executed upon conversion completion.
static func createConvertingAlertController(onConversionCompletion: @escaping () -> Void) -> UIAlertController {
// The title font corresponds to Dynamic Type style "Headline"
let titleFont = UIFont.preferredFont(forTextStyle: .headline)
let calculatorImageView = UIImageView(image: UIImage(named: "calculator.fill", in: nil, with: UIImage.SymbolConfiguration(font: UIFont.systemFont(ofSize: titleFont.pointSize * 2.0, weight: .semibold))))
let measuringAttributedStringHeight = NSAttributedString(string: "Penguin", attributes: [.font: titleFont]).boundingRect(with: .zero, options: [.usesFontLeading, .usesLineFragmentOrigin], context: nil).height
let desiredOffset = 15.0 + calculatorImageView.bounds.height
let totalNewlinePrefixes = Int((desiredOffset / measuringAttributedStringHeight).