Skip to content

Instantly share code, notes, and snippets.

View fitomad's full-sized avatar
👋
Swift + AI & ML & DL + Azure + AWS + C# & .NET

Adolfo fitomad

👋
Swift + AI & ML & DL + Azure + AWS + C# & .NET
View GitHub Profile
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 })
// 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)
/*
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: "@#_")
<html>
<head>
<title>La prueba</title>
<style>
.btn-hide
{
visibility: hidden;
}
.btn-show
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)
/// 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...
//
// 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
//
// 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)
//
// 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
{
//
// 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
//