Declared with lazy keyword • Lazy Stored properties can’t be a constant; for obvious reasons • Useful when the initial values are depends on outside factors
lazy var importer = DataImporter() var data = [String]() } let m = DataManager() // importer has not yet been created m.data.append("Element 1"); m.data.append("Element 2"); m.data.append("Element 3"); // Initialize on first access m.importer.import();
a = b; b = t } func swapString(inout a:String, inout b:String) { let t = a; a = b; b = t } var a = 10, b = 20 swapInt(&a, &b) var p = "iOS 7", q = "iOS 8" swapString(&p,&q)
a = b; b = t } func swapString(inout a:String, inout b:String) { let t = a; a = b; b = t } var a = 10, b = 20 swapInt(&a, &b) var p = "iOS 7", q = "iOS 8" swapString(&p,&q) // MARK: With Generics func Swap <T> (inout a: T, inout b: T) { let t = a; a = b; b = t } Swap(&a, &b); Swap(&p, &q);
a = b; b = t } func swapString(inout a:String, inout b:String) { let t = a; a = b; b = t } var a = 10, b = 20 swapInt(&a, &b) var p = "iOS 7", q = "iOS 8" swapString(&p,&q) // MARK: With Generics func Swap <T> (inout a: T, inout b: T) { let t = a; a = b; b = t } Swap(&a, &b); Swap(&p, &q);