我正在尝试根据开关创建 NSData,但在将选项添加到方法时遇到问题appendBytes
。添加 NSStringtest
给我一个错误。
例子:
- (void)selectCenterJustification:(int)option
{
NSMutableData *data;
NSString *test;
switch (option)
{
case 0:
test = @"\x0";
break;
case 1:
test = @"\x1";
break;
case 2:
test = @"\x2";
break;
}
// does not work because of "test"
[data appendBytes:"\x1b" "a", test length:3];
// working
[data appendBytes:"\x1b" "a" "\x1" length:3];
}
知道我该怎么做吗?