Objective c 指向对象枚举/标记以获取字符串,
我需要获得一个按钮枚举,以便在需要按钮名称的方法中使用Objective c 指向对象枚举/标记以获取字符串,,objective-c,Objective C,我需要获得一个按钮枚举,以便在需要按钮名称的方法中使用 enum { Arle = 1, Bain, ... }; arle = [UIButton buttonWithType:UIButtonTypeCustom]; arle.tag = Arle; 我不能指向arle.tag,因为它是一个双精度而不是一个字符串,有什么我可以指向的,以得到@“arle”作为结果吗?没有。在C中,无法将枚举自动转换为字符串 编辑: 您必须手动转换: static inlin
enum {
Arle = 1,
Bain,
...
};
arle = [UIButton buttonWithType:UIButtonTypeCustom];
arle.tag = Arle;
我不能指向arle.tag,因为它是一个双精度而不是一个字符串,有什么我可以指向的,以得到@“arle”作为结果吗?没有。在C中,无法将枚举自动转换为字符串 编辑: 您必须手动转换:
static inline NSString *enum2String(int value)
{
switch(value) {
case Arle: return @"Arle";
case Bain: return @"Bain";
default: return nil;
}
}
也许不是自动的,但有什么办法吗?