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
Post a Comment