This file contains hidden or 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
extension String { | |
private static let blockElements = (9600...9631) | |
.compactMap { Unicode.Scalar($0) } | |
.map { Character($0) } | |
static func blocks(_ length: Int = 8) -> String { | |
let choices = (1...length) | |
.map { _ in String.blockElements.randomElement()! } | |
return String(choices) |
This file contains hidden or 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
extension UIControl { | |
private class ClosureSleeve { | |
let closure: () -> Void | |
init(attachTo attachee: AnyObject, closure: @escaping () -> Void) { | |
self.closure = closure | |
objc_setAssociatedObject(attachee, "\(Int.random())", self, .OBJC_ASSOCIATION_RETAIN_NONATOMIC) | |
} | |
@objc |
This file contains hidden or 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
/* The SegueHandlerType pattern, as seen on [1, 2], adapted for the changed Swift 3 syntax. | |
[1] https://developer.apple.com/library/content/samplecode/Lister/Listings/Lister_SegueHandlerType_swift.html | |
[2] https://www.natashatherobot.com/protocol-oriented-segue-identifiers-swift/ | |
*/ | |
protocol SegueHandlerType { | |
// `typealias` has been changed to `associatedtype` for Protocols in Swift 3. | |
associatedtype SegueIdentifier: RawRepresentable |
NewerOlder