• 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: Why doesn't this crash?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Why doesn't this crash?


  • Subject: Re: Why doesn't this crash?
  • From: Jens Alfke <email@hidden>
  • Date: Sat, 10 Sep 2016 07:40:02 -0700

> On Sep 10, 2016, at 5:16 AM, Pascal Bourguignon <email@hidden> wrote:
>
> It returns nil by feature of Objective-C.
> Referencing the class will translate into a runtime class lookup which will return nil. Sending a message to nil  will return nil.

Well, not exactly. If you reference the class name as a literal, as in [AVPlayer alloc], that does result in a link-time reference to a symbol .objc_class_name_AVPlayer. If that class doesn’t exist when the app is being loaded, it will fail to launch with a fatal dyld error.

Things would work as you describe if the class were being looked up by name, like
	[[NSClassFromString(@“AVPlayer”) alloc] init]
since NSClassFromString would return Nil.

Andreas, I think the reason your code doesn’t crash is that the linker is importing AVFoundation as a weak library (probably because of the minimum OS version you declared at build time.) That means that if the library doesn’t exist at load-time, all of its symbols will point to null. Then things are as Pascal describes.

—Jens
_______________________________________________

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


  • Follow-Ups:
    • Re: Why doesn't this crash?
      • From: Julian <email@hidden>
References: 
 >Why doesn't this crash? (From: Andreas Falkenhahn <email@hidden>)
 >Re: Why doesn't this crash? (From: Pascal Bourguignon <email@hidden>)

  • Prev by Date: Progress Indicator
  • Next by Date: Re: Progress Indicator
  • Previous by thread: Re: Why doesn't this crash?
  • Next by thread: Re: Why doesn't this crash?
  • Index(es):
    • Date
    • Thread