• 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: object instance names generated on the fly?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: object instance names generated on the fly?


  • Subject: Re: object instance names generated on the fly?
  • From: Jeff Disher <email@hidden>
  • Date: Fri, 21 Mar 2003 22:19:35 -0500

Maybe I am missing something here but when I first read your post I thought you were referring to instantiated objects based on the name. If that is so then you can use "NSClassFromString" (documented in Foundation functions under "Objective-C Runtime" to do something like this:

NSString *myClassName = @"Some class name that could come from a variable";
id myObject = [[NSClassFromString(myClassName) alloc] init];

That will instantiate an instance of the class with the given name (or return nil if it doesn't exist).

If you are talking about mapping names to instances then using the NSMutableDictionary containing NSMutableArrays as lists of the instances for a given name is probably best (as described by the other posts).

What you are talking about with sel_registerName is a runtime function used to register a selector (or method, if you are used to other language terminology) with the runtime. That is to functions what the above example is to data. Note, however, that the low-level Obj-C runtime calls you are referring to below are usually not necessary (they are used by the compiler when building the runtime in code, for example) and you would probably like the look of the higher-level convenience functions in the Foundation "Objective-C Runtime" documentation.

Perhaps I am misinterpreting what you are looking for but this might be of interest to you either way. If you need clarification on any of this, don't hesitate to ask.

Hope that helps,
Jeff.


On Friday, March 21, 2003, at 09:45 PM, Ben Dougall wrote:

these look pretty hopeful for what i was on about:


sel_registerName and sel_getUid from pages 165/6 of the inside os x obj-c pdf
and SEL from page 195


sel_registerName:

Registers the name of a method with the Objective-C runtime system. This function
maps the name to a selector and returns the selector value.
SEL sel_registerName(const char *str);
str
A pointer to a C string. Pass the name of the method you wish to register.
function result A pointer of type


question is: is it possible to initiate an object with a name that's a
variable?
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


Jeff Disher
President and Lead Developer of Spectral Class
Spectral Class: Shedding Light on Innovation
http://www.spectralclass.com/
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: object instance names generated on the fly?
      • From: Ben Dougall <email@hidden>
References: 
 >Re: object instance names generated on the fly? (From: Ben Dougall <email@hidden>)

  • Prev by Date: Re: object instance names generated on the fly?
  • Next by Date: Re: Help Book Problems
  • Previous by thread: Re: object instance names generated on the fly?
  • Next by thread: Re: object instance names generated on the fly?
  • Index(es):
    • Date
    • Thread