我在这里有这个方法,每次按保存时都会运行:
-(void)setName:(NSString *)foodName andCarbs:(NSNumber *)carbAmount{
[self.userFoodDictionary setObject:(NSString *)foodName forKey:(NSString *)foodName];
NSString *value = [[NSString alloc] initWithFormat:@"%@ Value", foodName];
[self.userFoodDictionary setObject:(NSNumber *)carbAmount forKey:(NSString *)value];
[self.userFoodDictionary writeToFile:self.appDataPath atomically:YES];
}
据我了解,倒数第二行应将userFoodDictionary
属性保存到指定的属性列表路径。但这似乎不会发生一次。我重建应用程序。也许我创建新字典对象的方式不正确。有人可以解释为什么这不起作用吗?