[swift-users] _swift_abortRetainUnowned when capturing @objc class as unowned

Tadeas Kriz tadeas at brightify.org
Wed Dec 23 06:31:23 CST 2015


Hey,

I am experiencing this strange crashing when capturing an instance of a
@objc class (written in swift, but annotated with @objc and subclass of
NSObject). It happens when the closure is being assigned and not when
called, so the problem is not that the captured value would get deallocated
and then the closure called. It happens randomly, sometimes it crashes
sooner, sometimes later. I was experiencing this bug in earlier versions of
Swift (I think it was Swift 1.2), but now I'm using 2.1 and getting this
crash too.

It works well when I change `[unowned x]` to `[weak x]` and then access it
by force unwrapping `x!.doSomething()` which leads me to believe it is a
bug in Swift, rather than in my code. However before opening a ticket at
bugs.swift.org, I wanted to get more eyes on this to make sure I'm not
missing anything.

It was also mentioned here:
http://www.codeproject.com/Articles/791304/Resolving-strong-references-between-Swift-and-Obje
here:
https://www.reddit.com/r/swift/comments/3vhwmj/unowned_bug_in_closure_causes_attempted_to_retain/
and here:
https://forums.developer.apple.com/thread/9873
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20151223/82e81bc5/attachment.html>


More information about the swift-users mailing list