相关疑难解决方法(0)

Objective-C中的类属性列表

有没有办法获得某种类的属性数组?例如,如果我有这样的界面

@interface MyClass : NSObject
    @property (strong,nonatomic) UILabel *firstLabel;
    @property (strong,nonatomic) UILabel *secondLabel;        
@end
Run Code Online (Sandbox Code Playgroud)

我可以在不知道名字的情况下获得实施中的标签参考吗?

@implementation MyClass
    -(NSArray*)getListOfAllLabels
    {
            ?????
    }        
@end
Run Code Online (Sandbox Code Playgroud)

我知道我可以轻松地完成它[NSArray arrayWithObjects:firstLabel,secondLabel,nil],但我想用某种类枚举来做for (UILabel* oneLabel in ???[self objects]???)

class object objective-c ios

29
推荐指数
4
解决办法
3万
查看次数

在Objective-C中确定属性是否为int,float,double,NSString,NSDate,NSNumber等

我需要确定一个对象的属性(通过名称传递)类型,以便从XML执行反序列化.我有一些通用的伪代码(但是我不确定如何在Objective-C中执行这些比较):

id object = [[[Record alloc] init] autorelease];

NSString *element = @"date";
NSString *data = @"2010-10-16";

objc_property_t property = class_getProperty([object class], [element UTF8String]);
const char *attributes = property_getAttributes(property);

char buffer[strlen(attributes) + 1];
strcpy(buffer, attributes);

char *attribute = strtok(buffer, ",");
if (*attribute == 'T') attribute++; else attribute = NULL;

if (attribute == NULL);
else if (strcmp(attribute, "@\"NSDate\"") == 0) [object setValue:[NSDate convertToDate:self.value] forKey:element];
else if (strcmp(attribute, "@\"NSString\"") == 0) [object setValue:[NSString convertToString:self.value] forKey:element];
else if (strcmp(attribute, "@\"NSNumber\"") == 0) [object setValue:[NSNumber …
Run Code Online (Sandbox Code Playgroud)

iphone cocoa objective-c

14
推荐指数
1
解决办法
1万
查看次数

标签 统计

objective-c ×2

class ×1

cocoa ×1

ios ×1

iphone ×1

object ×1