Last active
October 3, 2016 13:50
-
-
Save hamishknight/fa473de76612ab76f53844d26cdacc3c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class Bar { | |
let id : Int | |
init(id: Int) { self.id = id } | |
} | |
class Foo { | |
var bar : Bar | |
init(bar: Bar) { self.bar = bar} | |
func printBar() { | |
print(bar.id) | |
} | |
} | |
let b = Bar(id: 5) | |
let f = Foo(bar: b) | |
let printMethod = f.printBar // if bar has been captured, the method will now always print b.id (5) | |
let b1 = Bar(id: 7) | |
f.bar = b1 | |
printMethod() // prints b1.id (7), thus no capturing |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment