Skip to content

Instantly share code, notes, and snippets.

View msewell's full-sized avatar

Michael Sewell msewell

View GitHub Profile
@msewell
msewell / blocks.swift
Created November 1, 2019 13:10
Random String containing of Block elements (an alternative to Lorem Ipsum?)
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)
@msewell
msewell / UIControl+ActionClosure.swift
Created January 24, 2018 16:37
UIControl.addAction(for:action:)
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
@msewell
msewell / SegueHandlerType.swift
Last active October 3, 2022 16:45
SegueHandlerType for Swift 3
/* 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