• 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: Ben Dougall <email@hidden>
  • Date: Sat, 22 Mar 2003 13:45:24 +0000

On Saturday, March 22, 2003, at 03:19 am, Jeff Disher wrote:

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).

jeff, thanks very much for the reply. if you have got the wrong end of the stick, i'm sure nearly all (if not all) the blame is on me. :) (that's obvious)

for a second, knee jerk reaction & first thing in the morning, i thought this might be exactly what i'm looking for. but i don't think it is. someghing like NSInstanceOfClassFromString could have been it, but obviously that's a made up name. i haven't looked into NSClassFromString in detail yet - i've got a few things to follow up - but from what i can understand immediately it doesn't look like what i'm looking for.


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).

yes, dictionary has been mentioned the most times so far. so that looks like the best one to follow up.


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.

yes, i now realise that stuff is related to methods(functions/selectors whatever) rather than object instances.

(they are used by the compiler when building the runtime in code, for example)

so not something that takes place on the fly then. right, that's not so useful.


i've got several things to follow up - arrays, dictionary, classfromstring. and even compiling on the fly. i've got plenty to go on for now. thanks v. much for your time and patience :)

ben.






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: j o a r <email@hidden>
References: 
 >Re: object instance names generated on the fly? (From: Jeff Disher <email@hidden>)

  • Prev by Date: Re: object instance names generated on the fly?
  • Next by Date: creating new instances
  • 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