Last active
September 11, 2019 13:15
-
-
Save frootloops/87e55b886883058d268c004dd81fe53a to your computer and use it in GitHub Desktop.
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
| import UIKit | |
| import Foundation | |
| final class MessageSender { | |
| private let api: API = TestAPI() | |
| func send(images: [UIImage], text: String, completion: @escaping () -> Void) { | |
| // TODO: please implement this method | |
| } | |
| } | |
| // MARK: API definition | |
| typealias ImageId = String | |
| protocol API: AnyObject { | |
| func uploadImage(_: UIImage, completion: @escaping (ImageId) -> Void) | |
| func sendMessage(imageIds: [ImageId], text: String, completion: @escaping () -> Void) | |
| } | |
| // MARK: API implementation | |
| class TestAPI: API { | |
| func uploadImage(_ image: UIImage, completion: @escaping (ImageId) -> Void) { | |
| DispatchQueue.global().asyncAfter(deadline: .now() + Double.random(in: 0..<1)) { | |
| completion(image.description) | |
| } | |
| } | |
| func sendMessage(imageIds: [ImageId], text: String, completion: @escaping () -> Void) { | |
| DispatchQueue.global().async { | |
| completion() | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment