Skip to content

Instantly share code, notes, and snippets.

@llinardos
Last active May 8, 2018 20:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save llinardos/7544cf4bc0febc709d0cbe56ba0aac11 to your computer and use it in GitHub Desktop.
Save llinardos/7544cf4bc0febc709d0cbe56ba0aac11 to your computer and use it in GitHub Desktop.
protocol ThingsService {
func getThings(onCompletion callback: (Result<[Thing]>) -> Void)
func add(onCompletion callback: (Result<Bool>) -> Void)
}
class FakeThingsService: ThingsService {
private(set) var things: [Thing]
init(things: [Thing]) {
self.things = things
}
func getThings(onCompletion callback: (Result<[Thing]>) -> Void) {
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0, execute: {
callback(.result(things))
})
}
func add(onCompletion callback: (Result<Bool>) -> Void) {
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0, execute: {
if things.contains(thing) {
callback(.success(false))
} else {
things.append(thing)
callback(.success(true))
}
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment