Re: Who owns a child view controller?
Re: Who owns a child view controller?
- Subject: Re: Who owns a child view controller?
- From: Jeremy Hughes <email@hidden>
- Date: Thu, 13 Jul 2017 12:05:26 +0100
> On 13 Jul 2017, at 11:26, Jeremy Hughes <email@hidden> wrote:
>
> So perhaps the difference between safe and unsafe unowned is that safe
> unowned generates a runtime error (but doesn’t crash) while unsafe unowned
> crashes? Or perhaps they both crash, but unowned(unsafe) gives a more helpful
> error message?
Here’s some playground code:
import Foundation
class Element
{
var name = "name"
}
var element1: Element? = Element()
unowned var element2 = element1!
element1 = nil
var element3 = element2
When Xcode (8.2.1) doesn’t crash (which seems to happen quite frequently with
playgrounds) I get the following error:
Execution was interrupted, reason: EXC_BREAKPOINT (code=EXC_I386_BPT,
subcode=0x0).
If I change unowned to unowned(unsafe) I sometimes get a more informative error:
Execution was interrupted, reason: EXC_BAD_ACCESS (code=1, address=0x20).
EXC_BAD_ACCESS is more informative than EXC_BREAKPOINT because it’s obviously a
memory error.
But sometimes I don’t get an error.
By inference, unowned is safer than unowned(unsafe) because it crashes
predictably. But this is tangential to other memory questions because I’m not
planning to use unowned(unsafe) in my own code.
Jeremy
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden