• 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: Why NSClassFromString(@"CADisplayLink")?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Why NSClassFromString(@"CADisplayLink")?


  • Subject: Re: Why NSClassFromString(@"CADisplayLink")?
  • From: Wim Lewis <email@hidden>
  • Date: Tue, 10 May 2011 10:13:59 -0700

On 10 May 2011, at 3:34 AM, Brian Bruinewoud wrote:
> Just curious, why does this work (compiles and runs):
>
>    displayLink = [NSClassFromString(@"CADisplayLink") displayLinkWithTarget: tapped selector:@selector(respond:)];
>
> But this doesn't link because the CADisplayLink class is missing:
>
>    displayLink = [CADisplayLink displayLinkWithTarget: tapped selector:@selector(respond:)];


Because the second one causes the linker to find the class in the frameworks you're actually linking against, but the first one searches the process at runtime for a class by that name. Unless you're prepared for NSClassFromString() to return Nil, you should use the second form (and supply the appropriate framework to the linker so that it can resolve the class reference to the specific class in that framework).

The first form works because something else in the process happens to have loaded something that refers to CADisplayLink, but there's no guarantee that that will be true.


_______________________________________________

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

References: 
 >Why NSClassFromString(@"CADisplayLink")? (From: Brian Bruinewoud <email@hidden>)

  • Prev by Date: Re: Call NSView's -drawRect method manually
  • Next by Date: Re: Call NSView's -drawRect method manually
  • Previous by thread: Re: Why NSClassFromString(@"CADisplayLink")?
  • Next by thread: Re: Why NSClassFromString(@"CADisplayLink")?
  • Index(es):
    • Date
    • Thread