Skip to content

Instantly share code, notes, and snippets.

@frootloops
Last active September 11, 2019 13:15
Show Gist options
  • Select an option

  • Save frootloops/87e55b886883058d268c004dd81fe53a to your computer and use it in GitHub Desktop.

Select an option

Save frootloops/87e55b886883058d268c004dd81fe53a to your computer and use it in GitHub Desktop.
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