我有一个枚举,我想将它的一个值传递给一个期望char *
直接而不是创建另一个变量的 Objective-C 方法。我该怎么办?
例如
typedef enum { value1 = 0xAA, value2 = 0xBB, value3 = 0xCC } myValue;
NSMutableData *data = [[NSMutableData alloc] init];
// want to pass in the enum directly as char * but won't work
[data appendBytes:(char *){ value1 } length: 1];
// this will work, why? and is this the best way?
[data appendBytes:(char []){ value1 } length: 1];