Re: Why doesn't this crash?
Re: Why doesn't this crash?
- Subject: Re: Why doesn't this crash?
- From: Julian <email@hidden>
- Date: Sat, 10 Sep 2016 21:48:42 -0700
Also worthy to note is that the +class method is implemented in a smart way
and does more or less what objc_getClass does, and will never crash. It's
the recommended general way to see if the class is available. (Jens correct
me if I'm wrong, no doubt you know more here than I do!)
On Sep 10, 2016 7:41 AM, "Jens Alfke" <email@hidden> wrote:
>
> > 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
_______________________________________________
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