> On 13 Jul 2017, at 11:26, Jeremy Hughes <moon.rab...@virginmedia.com> 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 (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to