Skip to content

Instantly share code, notes, and snippets.

@hamishknight
Last active October 3, 2016 13:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hamishknight/fa473de76612ab76f53844d26cdacc3c to your computer and use it in GitHub Desktop.
Save hamishknight/fa473de76612ab76f53844d26cdacc3c to your computer and use it in GitHub Desktop.
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