• 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: Looking up a NSString constant at runtime
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Looking up a NSString constant at runtime


  • Subject: Re: Looking up a NSString constant at runtime
  • From: Mark Ritchie <email@hidden>
  • Date: Mon, 04 Jan 2010 18:27:13 -0800

On 4/Jan/2010, at 4:24 PM, glenn andreas wrote:
> CFBundle has routines for looking up both functions and data by name.  It does require you figure out what framework the symbol comes from (and then get the corresponding CFBundle), but it is doable.

Cool, I didn't know that CFBundle exposed access to external symbols at run time!  I've always used nm (or some such) to look at the symbol table.   This was a fun exercise to work out how to get access to the value of the symbol at runtime.  Apologies if I've done something weird, I don't work in CF very often.

If you know the bundle identifier, then it would seem that this code will find the symbol and allow access to its value:

	CFBundleRef bundle = CFBundleGetBundleWithIdentifier(CFSTR("com.apple.AppKit"));
	if(bundle){
		NSString **pointer = (NSString **)CFBundleGetDataPointerForName (bundle, CFSTR("NSDeviceResolution"));
		if(pointer){
			NSLog(@"NSDeviceResolution = %@", *pointer);
		}
	}

If you don't know the bundle identifier then I assume you have to iterate over the available bundles (left as an exercise for someone else. ;-)

As to the usefulness of this, I can't say.  The original poster never said why they were trying to do so I don't know if this will be suitable for the task...  Today however, at this moment, it worked for me!
M.

_______________________________________________

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: Looking up a NSString constant at runtime
      • From: Scott Ribe <email@hidden>
References: 
 >Re: Looking up a NSString constant at runtime (From: David Alter <email@hidden>)
 >Re: Looking up a NSString constant at runtime (From: Scott Ribe <email@hidden>)
 >Re: Looking up a NSString constant at runtime (From: David Alter <email@hidden>)
 >Re: Looking up a NSString constant at runtime (From: Graham Cox <email@hidden>)
 >Re: Looking up a NSString constant at runtime (From: glenn andreas <email@hidden>)

  • Prev by Date: Re: Re: NSSearchField and bindings question
  • Next by Date: Question about multiple MOCs on shared PSC
  • Previous by thread: Re: Looking up a NSString constant at runtime
  • Next by thread: Re: Looking up a NSString constant at runtime
  • Index(es):
    • Date
    • Thread