Re: Why doesn't this crash?
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