我有一个枚举,我想将它的一个值传递给一个Objective-C方法,期望直接使用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];
你到底在期待什么方法来接收?它想要一个char *'。你期望枚举值最终以'char *'的形式传递? –
它表示的字节值。让我编辑我的例子。 – Boon