尝试将值写入plist时获取错误

时间:2013-05-09 10:53:06

标签: ios plist

我正在尝试将值写入plist,但有错误

代码:

NSString *path = [[NSBundle mainBundle] pathForResource:@"Properties" ofType:@"plist"];
    NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:path];
    [dict setObject:[NSNumber numberWithInt:Quant] forKey:@"Quant"];
    [dict writeToFile:path atomically:YES];

错误:

No visible @interface for 'NSDictionary' declares the selector 'setObject:forKey:'

1 个答案:

答案 0 :(得分:0)

您无法修改不可变的NSDictionary。你必须使用可变副本:

NSMutableDictionary *dict = [[[NSDictionary alloc] initWithContentsOfFile:path] mutableCopy];