objective c - get property from id class -


abc *abc=[abc new]; id property=abc.property; 

but:

id classname=nsclassfromstring(abc); id instance=[classname new];  id property=???????; 

i can't use instance.property,because id type.

i want known property (id)type class.

i try use:

[ainstanse propertyforkey:<#(nsstring *)#>]; [ainstanse propertynamed:<#(nsstring *)#>]; 

but program crashes...

can me, thanks.

there many ways

you can cast if know type @ compile time

id property=((myclass *)instance).myproperty; ((myclass *)instance).myproperty = property; 

or not using dot syntax

id property=[instance myproperty]; [instance setmyproperty:property]; 

or using valueforkey:

id property=[instance valueforkey:@"myproperty"]; [instance setvalue:property forkey:@"myproperty"]; 

Comments

Popular posts from this blog

user interface - Python attempting to create a simple gui, getting "AttributeError: 'MainMenu' object has no attribute 'intro_screen'" -

jquery - Common JavaScript snippet to share files on Google Drive, Dropbox, Box.net or SkyDrive -

Android Gson.fromJson error -