This file contains 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
/// | |
/// La aportación de **Louis Van Gaal** | |
/// al desarrollo del lenguaje Swift. | |
/// | |
/// La explicación en este vídeo de [Youtube](https://www.youtube.com/watch?v=Od5PQoRr7hU) | |
/// | |
extension SignedIntegerType | |
{ | |
/** | |
Convierte un número entero en negativo |
This file contains 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
// | |
// Swift version 2.2-dev (LLVM 3ebdbb2c7e, Clang f66c5bb67b, Swift 42591f7cba) | |
// Target: x86_64-unknown-linux-gnu | |
// | |
// [Swift IBM Sandbox](http://swiftlang.ng.bluemix.net/#/repl) | |
// | |
import Foundation | |
/// |
This file contains 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
/** | |
Execute closure after a delay | |
- Parameters: | |
-delay: Time to wait until execute closure | |
- closure: What is going to be executed | |
*/ | |
public func delay(delay: Double, closure: () -> ()) | |
{ | |
let time_gcd: dispatch_time_t = dispatch_time(DISPATCH_TIME_NOW, Int64(delay * Double(NSEC_PER_SEC))) |
This file contains 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
// | |
// Las variables `queue` y `timer` deben estar deblaradas | |
// como variables de la clase para así no perder la | |
// referencia. | |
// | |
// queue es de `tipo dispatch_queue_t` | |
// timer es de tipo `dispatch_source_t` | |
// | |
private func createTimer() -> Void | |
{ |
This file contains 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
// | |
// In *Swift 2* this works cause `private` means | |
// **inside this file** | |
// | |
// | |
// MARK: - A Class | |
// | |
internal class FilterView: UIView |
This file contains 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
// | |
// In *Swift 3* we have to change `private` in favor of `fileprivate` | |
// Now `private` means **accesible under the scope**, usually {...} and | |
// `fileprivate` is accesible inside the file. | |
// | |
// | |
// MARK: - A Class | |
// |
This file contains 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
// | |
// Definiendo el callback como tipo | |
// | |
typedef ResultCompletionHandler = (mensaje: String, tipo: String) -> (Void) | |
// | |
// Definido en la declaración del método | |
// | |
func findString(texto: String, completionHandler: (mensaje: String, tipo: String) -> (Void)) -> Void | |
{ |
This file contains 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
// | |
// Antes. Un callback por cada tipo devuelto | |
// | |
typedef ResultVenueCompletionHandler = (result: Venue) -> (Void) | |
typedef ResultHotelCompletionHandler = (result: Hotel) -> (Void) | |
// | |
// Ahora. Al poder ser definidos como genéricos con un tipo nos vale | |
// | |
typedef ResultCompletionHandler<T> = (T) -> (Void) |
This file contains 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
// | |
// Esta definición *no* le gusta al compilador de `Swift 3` | |
// | |
typealias ResultCompletionHandler<T, U> = (message: T, tipo: U) -> (Void) | |
/* | |
ERROR at line 3, col 44: function types cannot have argument label 'message'; use '_' instead | |
typealias ResultCompletionHandler<T, U> = (message: T, tipo: U) -> (Void) | |
ERROR at line 3, col 56: function types cannot have argument label 'tipo'; use '_' instead |
This file contains 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... |