[swift-users] Is 'self' retained instead of member-function?
Daniel Tartaglia
danielt1263 at gmail.com
Wed Feb 10 14:33:51 CST 2016
In the code below, I’m confused as to wether ‘self’ is owned, unowned or retained inside the ‘bar()’ function. I was assuming that it would always be retained, but I am wondering if that’s correct… Especially the ‘unownedThunk’ example… I don’t recall anything in the Swift book explicitly answering this question.
class Foo {
init() {
ownedThunk = {
self.bar()
}
unownedThunk = { [unowned self] in
self.bar()
}
weakThunk = { [weak self] in
self?.bar()
}
}
func bar() {
// is 'self' owned/unowned/weak? here?
}
private var ownedThunk: () -> Void = { }
private var unownedThunk: () -> Void = { }
private var weakThunk: () -> Void = { }
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20160210/c687fda1/attachment.html>
More information about the swift-users
mailing list