• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Who owns a child view controller?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

References: 
 >Who owns a child view controller? (From: Jeremy Hughes <email@hidden>)
 >Re: Who owns a child view controller? (From: Jens Alfke <email@hidden>)
 >Re: Who owns a child view controller? (From: Jeremy Hughes <email@hidden>)
 >Re: Who owns a child view controller? (From: Jens Alfke <email@hidden>)
 >Re: Who owns a child view controller? (From: Charles Srstka <email@hidden>)
 >Re: Who owns a child view controller? (From: Jeremy Hughes <email@hidden>)
 >Re: Who owns a child view controller? (From: Jens Alfke <email@hidden>)
 >Re: Who owns a child view controller? (From: Jeremy Hughes <email@hidden>)
 >Re: Who owns a child view controller? (From: Steve Christensen <email@hidden>)
 >Re: Who owns a child view controller? (From: Quincey Morris <email@hidden>)
 >Re: Who owns a child view controller? (From: Jeremy Hughes <email@hidden>)
 >Re: Who owns a child view controller? (From: Quincey Morris <email@hidden>)
 >Re: Who owns a child view controller? (From: Jeremy Hughes <email@hidden>)
 >Re: Who owns a child view controller? (From: Jeremy Hughes <email@hidden>)

  • Prev by Date: Re: Who owns a child view controller?
  • Next by Date: Question about structs and enum placement in a project
  • Previous by thread: Re: Who owns a child view controller?
  • Next by thread: Re: Who owns a child view controller?
  • Index(es):
    • Date
    • Thread