Author: Chris Lattner
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright © 2019 Alexey Naumov. MIT License | |
import Combine | |
typealias CancelBag = Set<AnyCancellable> | |
extension CancelBag { | |
mutating func collect(@Builder _ cancellables: () -> [AnyCancellable]) { | |
formUnion(cancellables()) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lazy var accessoryToolbarWithDoneButton: UIToolbar = { | |
let toolbar = UIToolbar(frame: CGRect.zero) | |
//only needs to be flexible in the dimension(s) you want it to be | |
//https://stackoverflow.com/questions/31822504/how-can-i-increase-the-height-of-an-inputaccessoryview | |
toolbar.autoresizingMask = [.flexibleWidth, .flexibleHeight] | |
let leftSpace = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil) | |
let doneButton = UIBarButtonItem(barButtonSystemItem: .done, target: self, action: #selector(keyboardDoneButtonTapped(_:))) | |
toolbar.items = [leftSpace, doneButton] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct FailableDecodable<Base: Decodable>: Decodable { | |
var base: Base? | |
init(from decoder: Decoder) throws { | |
let container = try decoder.singleValueContainer() | |
do { | |
base = try container.decode(Base.self) | |
} catch let error { | |
print(error) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
typedef CF_ENUM(int, CFNetworkErrors) { | |
kCFHostErrorHostNotFound = 1, | |
kCFHostErrorUnknown = 2, // Query the kCFGetAddrInfoFailureKey to get the value returned from getaddrinfo; lookup in netdb.h | |
// SOCKS errors; in all cases you may query kCFSOCKSStatusCodeKey to recover the status code returned by the server | |
kCFSOCKSErrorUnknownClientVersion = 100, | |
kCFSOCKSErrorUnsupportedServerVersion = 101, // Query the kCFSOCKSVersionKey to find the version requested by the server | |
// SOCKS4-specific errors | |
kCFSOCKS4ErrorRequestFailed = 110, // request rejected or failed by the server | |
kCFSOCKS4ErrorIdentdFailed = 111, // request rejected because SOCKS server cannot connect to identd on the client |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//: Playground - noun: a place where people can play | |
import UIKit | |
var str = "Anonymous Class in Swift" | |
//https://stackoverflow.com/questions/24408068/anonymous-class-in-swift | |
//There is no equivalent syntax. | |
//Regarding equivalent techniques, theoretically you could use closures and define structs and classes inside them. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import SceneKit | |
let json = """ | |
{ | |
"position": [2.0, 5.0, 3.0], | |
"rotation": [0.0, 0.73, 0.0, 0.73] | |
} | |
""".data(using: .utf8)! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public extension CustomDebugStringConvertible { | |
var debugDescription: String { | |
return debugDescription() | |
} | |
func debugDescription(_ indentationLevel: Int = 0, includeType: Bool = true) -> String { | |
let indentString = (0..<indentationLevel).reduce("") { tabs, _ in tabs + "\t" } | |
var s: String |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function logClass(target: any) { | |
// save a reference to the original constructor | |
var original = target; | |
// a utility function to generate instances of a class | |
function construct(constructor, args) { | |
var c : any = function () { | |
return constructor.apply(this, args); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol Initializable { | |
init() | |
} | |
class A : Initializable { | |
var content:String | |
required init() { | |
content = "TestContent" | |
} |
NewerOlder