Skip to content

Instantly share code, notes, and snippets.

View fitomad's full-sized avatar
🫥
Swift + AI/ML/ DL + Azure + AWS + Vapor + Hummingbird

Adolfo fitomad

🫥
Swift + AI/ML/ DL + Azure + AWS + Vapor + Hummingbird
View GitHub Profile
@fitomad
fitomad / private-fileprivate-swift2.swift
Last active August 24, 2016 08:09
Usage of private access modifier in Swift 2
//
// In *Swift 2* this works cause `private` means
// **inside this file**
//
//
// MARK: - A Class
//
internal class FilterView: UIView
//
// 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
{
/**
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)))
//
// 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
///
///
/// 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
///
/// Prueba de rendimiento para la operacion
/// de recuperacion de datos para una serie de TV
///
func testShow()
{
// Manhattan Love Story
let showID: Int = 281624
// Closure de rendimiento
func testMovie()
{
// 214756 - Ted 2
// Este es el semaforo
let semaphore: dispatch_semaphore_t = dispatch_semaphore_create(0)
FanartClient.sharedInstance.fanartForMovie(214756) { (movie, error) -> (Void) in
// Comprobamos si hay error...
XCTAssertNil(error, "Se ha producido un error en el framework")
func testMovie()
{
// 214756 - Ted 2
// Creamos el objeto que nos ayudara a probar
// la operacion asincrona
let expectation: XCTestExpectation = self.expectationWithDescription("Test fanartForMovie()...")
FanartClient.sharedInstance.fanartForMovie(214756) { (movie, error) -> (Void) in
// Comprobamos si hay error...
// Creacion de un semaforo
let semaphore: dispatch_semaphore_t = dispatch_semaphore_create(0)
// Liberamos el semaforo.
//La ejecuion puede continuar
dispatch_semaphore_signal(semaphore)
// Este es el punto de bloqueo.
// Aqui esperamos a que se llame
// a la funcion `dispatch_semaphore_signal(sem)`
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER)
let fixed_array: [Int] = [ 2, 1, 4, 3, 6, 5, 8, 7, 10, 9]
var mutable_array: [Int] = [ 2, 8, 10, 3, 6, 5, 4, 7, 1, 9]
let new_fixed_array = fixed_array.sort()
mutable_array.sortInPlace()
print("> mutable: \(mutable_array.descriptionWithSeparator(", "))")
print("> fixed: \(fixed_array.descriptionWithSeparator(", "))")
print("> new fixed: \(new_fixed_array.descriptionWithSeparator(", "))")