1

我正在尝试将值写入 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:'
4

1 回答 1

0

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

NSMutableDictionary *dict = [[[NSDictionary alloc] initWithContentsOfFile:path] mutableCopy];
于 2013-05-09T10:56:41.437 回答