[编码encodeValuesOfObjCTypes - 我在这里放什么?

时间:2012-03-24 21:33:58

标签: iphone objective-c

这是我到目前为止所尝试的,正如各种网站所建议的那样:

[encoder encodeValuesOfObjCTypes:@encode(BOOL), self.isInPhotoLibrary];
[encoder encodeValuesOfObjCTypes:"i", self.isInPhotoLibrary];
[encoder encodeValuesOfObjCTypes:(const char *)self.isInPhotoLibrary];

所有这3次崩溃。有谁知道如何使用它? self.isInPhotoLibrary是一个BOOL。

2 个答案:

答案 0 :(得分:5)

我认为使用keyed archiving method

会更简单
[encoder encodeBool:[self isInPhotoLibrary] forKey:@"isInPhotoLibrary"];

答案 1 :(得分:3)

documentation for -encodeValuesOfObjCTypes:州:

  

此方法的变量参数由一个或多个指针组成   参数,每个参数指定一个包含值的缓冲区   编码。对于valueTypes中的每个类型代码,您必须指定一个   相应的指针参数。

您传入的是值,而不是指针。这样做:

BOOL value = self.isInPhotoLibrary;
[encoder encodeValuesOfObjCTypes:@encode(BOOL), &value];

或者,因为您只编码一个值:

BOOL value = self.isInPhotoLibrary;
[encoder encodeValueOfObjCType:@encode(BOOL) at:&value];
相关问题