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.
The only caveat is that a class with that name could be provided by a library and invalidate your code. But I would say improbable, and I would count on it. Just be careful to never dereference those nils! -- __Pascal Bourguignon__ > Le 10 sept. 2016 à 13:39, Andreas Falkenhahn <andr...@falkenhahn.com> a écrit > : > > I want my app to run on 10.6 but use 10.7 features where available. Thus I'm > compiling on 10.11 using -mmacosx-version-min=10.6. In particular, I want to > use AVFoundation to play videos on 10.7 and better. > > To open a video, I do the following: > > AVPlayer *p = [[AVPlayer alloc] initWithURL:url]; > > I'd expect this code to crash on 10.6 because 10.6 doesn't have AVPlayer. > To my surprise, however, the code doesn't crash and it just returns NULL. > This is fine because then my app will just show a message box informing > the user that the file couldn't be opened and no other AVFoundation APIs > will be accessed. > > However, I'm wondering whether it is ok to execute this code on 10.6 without > any safeguard. I thought I'd have to do something like this instead: > > if(floor(NSAppKitVersionNumber) >= NSAppKitVersionNumber10_7) { > > AVPlayer *p = [[AVPlayer alloc] initWithURL:url]; > ... > > } else { > > return NULL; > } > > Do I have to do this or can I just rely on alloc/init returning NULL for > classes unknown on 10.6? > > -- > Best regards, > Andreas Falkenhahn mailto:andr...@falkenhahn.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/pjb%40informatimago.com > > This email sent to p...@informatimago.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