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
enum Parked {} | |
enum Driving {} | |
enum Gaming {} | |
private class EngineSystem { | |
static var shared = EngineSystem() | |
private init() {} | |
func start() {/**/} | |
func accelerate() { /* Uses gas pedal input to accelerate the real car */ } |
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
// My new website. A lot of Type-Driven Design/Development content is coming in the next few weeks. Stay tuned. | |
https://swiftology.io | |
// All articles used in the talk | |
https://lexi-lambda.github.io/blog/2019/11/05/parse-don-t-validate/ | |
https://www.parsonsmatt.org/2017/10/11/type_safety_back_and_forth.html | |
https://pragprog.com/titles/swdddf/domain-modeling-made-functional/ | |
https://blog.codinghorror.com/falling-into-the-pit-of-success/ | |
https://github.com/pointfreeco/swift-tagged | |
https://existentialtype.wordpress.com/2011/03/15/boolean-blindness/ |
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 final class RealmWrapper { | |
private let _workerQueue = DispatchQueue(label: "RealmWrapper", | |
qos: .utility) | |
/// Creates Realm object on designated thread. This gives you oportunity to query some object in a thread-safe environment or resolve ThreadSafeReference before performing writes. | |
/// | |
/// - Parameter block: accepts a newely created Realm object. which relates to a designated database thread. | |
public func open(_ block: @escaping (Realm?) -> Void) { | |
_workerQueue.async { | |
do { | |
block(try Realm()) |
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
func syncGetter<T>(block: (@escaping (T?) -> Void) -> Void) -> T? { | |
let dispatchGroup = DispatchGroup() | |
var returnValue: T? | |
dispatchGroup.enter() | |
block() { value in | |
returnValue = value | |
dispatchGroup.leave() | |
} | |
dispatchGroup.wait() | |
return returnValue |
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
func synchronized<T>(_ object: Any, block: () -> T) -> T { | |
objc_sync_enter(object) | |
let result = block() | |
objc_sync_exit(object) | |
return result | |
} |
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 class AsyncOperation: Operation { | |
public enum OperationError: Error { | |
case cancelled | |
} | |
public var isFailed: Bool = false | |
private var _completion: (Error?) -> Void | |
private var _execution: ((Error?) -> Void) -> Void | |
private var _isFinished = false | |
private var _isExecuting = false |
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
extension SequenceType { | |
/** | |
Return an Optional<Array> containing the non-nil results of mapping transform over self or nil if any transform fails. | |
Complexity: O(N). | |
*/ | |
public func failingMap<T>(@noescape transform: (Self.Generator.Element) throws -> T?) rethrows -> [T]? { | |
let initialCapacity = self.underestimateCount() | |
var result = ContiguousArray<T>() | |
result.reserveCapacity(initialCapacity) |