[swift-users] Is 'self' retained instead of member-function?

Joe Groff jgroff at apple.com
Wed Feb 10 18:12:49 CST 2016


Yeah, 'self' is always a strong reference if it isn't overridden by a capture list declaration, as are all arguments.

-Joe

> On Feb 10, 2016, at 12:33 PM, Daniel Tartaglia via swift-users <swift-users at swift.org> wrote:
> 
> 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 = { }
> 
> }
> 
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20160210/daffb334/attachment.html>


More information about the swift-users mailing list