Created
August 24, 2016 08:39
-
-
Save fitomad/a22ceeffc7a0c0717d9b9ea47419e202 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
| /// Callback genérico | |
| typealias ResultCompletionHandler<T, U> = (_ message: T, _ tipo: U) -> (Void) | |
| // | |
| // Los métodos a los que llamaría el usuario... | |
| // | |
| public func findString(url: String, handler: ResultCompletionHandler<String, String>) -> Void | |
| { | |
| // Hacemos cosas chulas... | |
| handler("Hola", "String") | |
| } | |
| public func findInt(url: String, handler: ResultCompletionHandler<Int, String>) -> Void | |
| { | |
| // Hacemos otras cosas chulas... | |
| handler(8, "Int") | |
| } | |
| // | |
| // Vamos *buscar* un `String` | |
| // | |
| findString(url: "http://desappstre.com", handler: { (message: String, tipo: String) -> (Void) in | |
| print("Message: \(message), of type \(tipo)") | |
| }) | |
| // | |
| // Vamos *buscar* un `Int` | |
| // | |
| findInt(url: "http://desappstre.com", handler: { (message: Int, tipo: String) -> (Void) in | |
| print("Mensaje: \(message), of type \(tipo)") | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment