• 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: Weak-linking a class
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Weak-linking a class


  • Subject: Re: Weak-linking a class
  • From: Andy Lee <email@hidden>
  • Date: Sun, 27 Jun 2010 09:55:16 -0400

NSClassFromString()?  Or maybe some objc_xxx runtime function?

--Andy


On Jun 27, 2010, at 9:50 AM, Graham Cox wrote:

> How do I test for the existence of a Cocoa class at runtime that could be absent on an earlier system?
>
> The situation is that I want to use NSCache instead of NSMutableDictionary somewhere. The object is created as a singleton when it's first used, but I can't quite see how I should decide which class to make. I've read the weak-linking guide and it makes sense, but the example in there shows only a simple C function, not an Obj-C class.
>
> I'm setting 10.6 SDK as my base SDK, but my minimum deployment target is 10.5. Therefore NSCache will not be there on 10.5.
>
> I thought I could do e.g.:
>
> if([NSCache alloc] == nil ){ ... fall back to NSMutableDictionary ... }
>
> but on 10.6 that actually calls [NSCache alloc] which I don't want, I just want to test whether [NSCache alloc] (or any appropriate class method) actually exists or not, or more precisely, whether NSCache exists. I'm guessing it's easy and probably obvious when you know it, but I'm not seeing it.
>
> --Graham
>
>
>
>
> _______________________________________________
>
> 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

  • Follow-Ups:
    • Re: Weak-linking a class
      • From: Graham Cox <email@hidden>
References: 
 >Weak-linking a class (From: Graham Cox <email@hidden>)

  • Prev by Date: Weak-linking a class
  • Next by Date: Re: Weak-linking a class
  • Previous by thread: Weak-linking a class
  • Next by thread: Re: Weak-linking a class
  • Index(es):
    • Date
    • Thread