Created
January 22, 2016 12:31
-
-
Save qnoid/7008c4d7abc226d99913 to your computer and use it in GitHub Desktop.
In a capture list, there is no need to capture a reference to "self" if you need a reference to an instance self holds. https://twitter.com/qnoid/status/690507191057551360
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
class ViewController : UIViewController | |
{ | |
var foo = "foo" | |
func hello() | |
{ | |
let closure = { [foo = self.foo] in | |
print("Hello \(foo)!") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
“Capture Lists
By default, a closure expression captures constants and variables from its surrounding scope with strong references to those values. You can use a capture list to explicitly control how values are captured in a closure.”
Excerpt From: Apple Inc. “The Swift Programming Language (Swift 2.1).” iBooks. https://itun.es/gb/jEUH0.l