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" <j...@mooseyard.com> wrote: > > > On Sep 10, 2016, at 5:16 AM, Pascal Bourguignon <p...@informatimago.com> > 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 (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/jpellico%40gmail.com > > This email sent to jpell...@gmail.com _______________________________________________ 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