我有一個枚舉,我想將它的一個值傳遞給一個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