我从NSObject的无法保存到PList
继承了我自己的对象类@interface BlockedCell : NSObject
{
NSValue *gridValue;
NSString *name;
}
@property (nonatomic, retain) NSValue *gridValue;
@property (nonatomic, retain) NSString *name;
@end
所以我尝试创建几个对象:
NSMutableDictionary *dict = [[dict alloc] init];
for (int i = 0; i < 5; ++i)
{
BlockedCell *block = [[BlockedCell alloc] init];
block.gridValue = [NSValue valueWithCGPoint: CGPointMake(0.0f, 0.0f)];
block.name = @"something";
[dict setObject: block forKey: [NSString stringWithFormat: @"item_%d", i]];
[block release];
}
if([dict writeToFile: path atomic: YES])
NSLog(@"Saved");
else
NSLog(@"Failed to save");
[dict release];
而我得到的输出是“无法保存” .. 如果我的字典里没有包含任何数据,则输出“拯救”
编辑: 我做更多的测试后,我发现居然是导致保存失败的NSValue。 那么如果我想将CGPoint保存为plist,我该怎么做?
谢谢,很好地解释:) – 2011-12-14 05:39:10