Skip to content

Instantly share code, notes, and snippets.

@leopic
Created December 1, 2016 22:44
Show Gist options
  • Save leopic/1e004211f6e484fb9e8f03e27a4b1fb7 to your computer and use it in GitHub Desktop.
Save leopic/1e004211f6e484fb9e8f03e27a4b1fb7 to your computer and use it in GitHub Desktop.
A couple of Swift 3 things that I got confused by
import Foundation
// @escape VS @no-escaping
class Uno {
func closure(completion: () -> Void) {
// Non-escaping
completion()
// Escaping
// DispatchQueue.main.asyncAfter(deadline: .now() + 5, execute: {
// completion()
// })
}
}
class Dos {
let uno = Uno()
func test() {
uno.closure {
print("hola!")
}
}
}
let dos = Dos()
dos.test()
// Any vs AnyObject
class Tres: NSObject {}
let fiveAsNSNumber:NSNumber = 5
// This is an array of NSObject, everything is tied to a root class, usually NSObject
let anyObjectArray = [Tres(), fiveAsNSNumber]
class Cuatro {}
let fiveAsInt = 5
let fn = { print("closure") }
// This is an array of Any, basically anything can go in here
let anyArray:[Any] = ["a", fiveAsInt, fn, Cuatro()]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment