• 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: create object from class name held in String?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: create object from class name held in String?


  • Subject: Re: create object from class name held in String?
  • From: Darren Minifie <email@hidden>
  • Date: Thu, 30 Apr 2009 13:55:53 -0700

Thanks everyone.  Guess i was the only mac developer who didn't know
that.... :)

On Thu, Apr 30, 2009 at 1:06 PM, Jonathan Hess <email@hidden> wrote:

> Hey Darren -
>
> Try NSClassFromString.
>
> Animal* anAnimal = [[NSClassFromString(@"Dog") alloc] init]
>
> Jon Hess
>
>
> On Apr 30, 2009, at 12:50 PM, Darren Minifie wrote:
>
>  Hi everyone.
>>
>> I have the situation where I need to dynamically create an object based on
>> the value held in a string at runtime.  I'm pretty sure the dynamic nature
>> of objective-c would allow this, but I cant seem to find the right method
>> on
>> NSString or NSObject.  I want to do this:
>>
>> NSString* someClass = @"Dog";
>> Animal* anAnimal = [[someClass alloc] init];
>>
>> I know this isn't right, but I'm trying to use the value held in someClass
>> as the name of the class I want to instantiate.  thanks for the help.
>>
>>
>> --
>> Darren Minifie
>> Graduate Studies: Computer Science
>> www.myavalon.ca
>> www.ohsnapmusic.com
>> _______________________________________________
>>
>> 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
>>
>
>


--
Darren Minifie
Graduate Studies: Computer Science
www.myavalon.ca
www.ohsnapmusic.com
_______________________________________________

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: 
 >create object from class name held in String? (From: Darren Minifie <email@hidden>)
 >Re: create object from class name held in String? (From: Jonathan Hess <email@hidden>)

  • Prev by Date: Creating a custom hierarchical list view
  • Next by Date: Re: virtual keycode to character
  • Previous by thread: Re: create object from class name held in String?
  • Next by thread: NSSavePanel runModalForDirectory, set name selection?
  • Index(es):
    • Date
    • Thread