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 ThingsServiceDelegate { | |
func service(_ ThingsService, didFinishWithResult: Result<[Thing]>) | |
} | |
class ThingsService { | |
private var delegate: ThingsServiceDelegate | |
init(with delegate: ThingsServiceDelegate) { | |
self.delegate = delegate | |
} |
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 getThings(onCompletion callback: (Result<[Thing]>) -> Void) { ... } |
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
let successResult: Result<[Thing]> = .success([aThing, anotherThing]) | |
let failureResult: Result<[Thing]> = .failure(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
let successResult: ([Thing]?, Error?) = ([aThing, anotherThing], nil) | |
let failureResult: ([Thing]?, Error?) = (nil, 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
let service = ThingsService() | |
activityIndicator.startAnimating() | |
service.getThings { getThingsResult in | |
activityIndicator.stopAnimating() | |
updateUI(with: getThingsResult) | |
} |
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
let syncService = SyncronicThingsService() | |
activityIndicator.startAnimating() | |
DispatchQueue.global(qos: .background).async { | |
let getThingsResult = syncService.getThings() | |
DispatchQueue.main.async { | |
activityIndicator.stopAnimating() | |
updateUI(with: getThingsResult) | |
} | |
} |
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
class Tap { | |
private static var instances: [Tap] = [] | |
// ... | |
static func on(view: UIView, fires action: @escaping () -> Void) { | |
let tap = Tap(view: view, action: action) | |
Tap.instances.append(tap) | |
} | |
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 aMethod() { | |
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(onTap(_:))) | |
aView.addGestureRecognizer(tapGesture) | |
} | |
@objc func onTap(_ gesture: UIGestureRecognizer) { | |
if (gesture.state == .ended) { | |
/* action */ | |
} | |
} |
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 aMethod() { | |
aView.onTap { /* action */ } | |
// or | |
Tap.on(aView) { /* action */ } | |
} |
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
class Tap { | |
private var view: UIView | |
private var action: () -> Void | |
init(view: UIView, action: @escaping () -> Void) { | |
self.view = view | |
self.action = action | |
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(onTap(_:))) | |
view.addGestureRecognizer(tapGesture) |