Skip to content

Instantly share code, notes, and snippets.

Avatar
:octocat:
Swift + Machine Learning + Big Data

Adolfo fitomad

:octocat:
Swift + Machine Learning + Big Data
View GitHub Profile
View protocols+classes+structs.swift
//
// 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
///
View create-dispatch-timer.swift
//
// 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
{
View private-fileprivate-swift3.swift
//
// 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
//
@fitomad
fitomad / private-fileprivate-swift2.swift
Last active Aug 24, 2016
Usage of private access modifier in Swift 2
View private-fileprivate-swift2.swift
//
// In *Swift 2* this works cause `private` means
// **inside this file**
//
//
// MARK: - A Class
//
internal class FilterView: UIView
View callback-antes.swift
//
// 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
{
View callback-ahora.swift
//
// 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)
View callback-ahora-named-parameters.swift
//
// 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
View callback-generico-swift3.swift
/// 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...
View delay-execution.swift
/**
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)))
View print-dump.swift
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)
You can’t perform that action at this time.