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
import Foundation | |
extension Array where Element: Comparable | |
{ | |
/** | |
Saludamos en orden a todos los integrantes del `Array`. | |
*/ | |
public func saluteAllElements() -> Void | |
{ | |
let sorted_elements: [Element] = self.sorted(by: { $0 < $1 }) |
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
// Números del 0 al 10 pero con el **5** un poco *descolocaldo* | |
let numeros: [Int] = [ 0, 1, 2, 3, 4, 6, 7, 8, 9, 5, 10 ] | |
// Swift 3.1 | |
let menores = numeros.prefix(while: { $0 < 5 }) | |
let mayores = numeros.drop(while: { $0 < 5 }) | |
dump(menores) | |
/* |
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
import Foundation | |
let tweet: String = "Detectar etiquetas y usuario en un tuit con #Swift. También podemos recoger los usuario como @fitomad o @AppStore. #SwiftLang #iOSDev #macOSDev" | |
// Estos caracteres no nos interesan... | |
var skip_set: CharacterSet = CharacterSet.whitespacesAndNewlines | |
skip_set.formUnion(CharacterSet.punctuationCharacters) | |
// ...excepto estos, que son para usuarios y etiquetas y no debemos excluirlos. | |
skip_set.remove(charactersIn: "@#_") |
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
<html> | |
<head> | |
<title>La prueba</title> | |
<style> | |
.btn-hide | |
{ | |
visibility: hidden; | |
} | |
.btn-show |
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
import Foundation | |
public class Team | |
{ | |
// Nombre del equipo | |
public var name: String | |
// Cuando se ha creado | |
public private(set) var createdAt: Date | |
public init(named name: String) |
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... |
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
// | |
// 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
// | |
// 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
// | |
// 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 | |
// |