Created
December 1, 2016 22:44
-
-
Save leopic/1e004211f6e484fb9e8f03e27a4b1fb7 to your computer and use it in GitHub Desktop.
A couple of Swift 3 things that I got confused by
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 | |
// @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