嗨,我正在尝试从餐馆对象创建一个fourates 列表,我的应用程序有一个不同餐馆的列表,我希望用户能够添加最喜欢的餐馆,但此代码不起作用
- (IBAction)toggleFav:(id)sender {
Restaurant *resto = [self restaure];
NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
[dic setObject:resto.price forKey:@"restoPrice"];
[dic setObject:resto.restaurantId forKey:@"restaurantId"];
[dic setObject:resto.restoAbout forKey:@"restoAbout"];
[dic setObject:resto.restoAddress forKey:@"restoAddress"];
[dic setObject:resto.restoBeverages forKey:@"restoBeverages"];
[dic setObject:resto.restoCategory forKey:@"restoCategory"];
[dic setObject:resto.restoEmail forKey:@"restoEmail"];
[dic setObject:resto.restoLogo forKey:@"restoLogo"];
[dic setObject:resto.restoName forKey:@"restoName"];
[dic setObject:resto.restoPhone forKey:@"restoPhone"];
[dic setObject:resto.restoCity forKey:@"restoCity"];
NSArray *dicArray = [dic allKeys];
if([sender isSelected]){
//...
[sender setSelected:NO];
NSMutableArray *array = [[[NSUserDefaults standardUserDefaults] objectForKey:@"restoName"] mutableCopy];
[array removeObject:dicArray];
[[NSUserDefaults standardUserDefaults] setObject:array forKey:@"restoName"];
} else {
//...
[sender setSelected:YES];
NSMutableArray *array = [[[NSUserDefaults standardUserDefaults] objectForKey:@"restoName"] mutableCopy];
[array addObject:dicArray];
[[NSUserDefaults standardUserDefaults] setObject:array forKey:@"restoName"];
[[NSUserDefaults standardUserDefaults] synchronize];
//NSLog(@"%@",[[NSUserDefaults standardUserDefaults] stringForKey:@"restoName"]);
}
}
' 类 '__NSCFArray'。请注意,属性列表中的字典和数组也必须只包含属性值。