Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/// 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