iphone中有沒有方法使用NSString獲取property,並且保留property?
@interface MyLovelyClass : NSObject
@property (nonatomic) double test;
-(double) returnDoubleProperty:(NSString *) propertyName;
然後調用:
MyLovelyClass *mlc=[ [MyLovelyClass alloc] init];
double value=[mlc returnDoubleProperty:@"test"];
如果知道某個類的屬性名來得到這個屬性的值,可以使用KVC
MyLovelyClass *mlc=[ [MyLovelyClass alloc] init];
double value=[[mlc valueForKey:@"test"] doubleValue];