Tag: 属性列表

如何存储相对静态但可configuration的信息

我有一个表(词典字典)来存储整数映射到string。 我有types和子types。 例如键入1 =>水果和子types1 =>苹果。 映射应该可以在我的设置界面中configuration,但是对于应用程序的重置来说,它是相当静态的。 所以我不想每次检查映射时都从属性列表读取数据。 我只想在程序启动时只读一次,只有在用户更改设置时才写入。 我应该在运行时保留这张表? 我有两种方法:(1)将整个表作为variables放在应用程序委托中,在这种情况下,每次需要获取string时,都需要使用objectForKey两次。 (2)是用一个静态variables创build一个类(不知道该怎么做),并使用类方法得到映射eg +(NSString)stringForType:subType: 你能否评估这两种方法或提出更好的解决scheme? 非常感谢!

尝试插入非属性值Objective C

嗨,我想创build一个餐馆对象,我的应用程序有不同的餐馆列表,我希望能够为用户添加优惠餐厅,这个代码是不工作 – (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]){ […]

NSNumber与NSString映射的NSDictionary是非属性列表对象

以下代码: [[NSUserDefaults standardUserDefaults] setObject:photoIdToPath forKey:@"photo_id_to_path"]; 给我以下错误: Attempt to set a non-property-list object { 417675729 = "/Users/k06a/Library/Application Support/iPhone Simulator/7.1/Applications/21163736-DF6F-4E79-8196-6A966C81ED1B/Documents/417675729"; } as an NSUserDefaults value for key photo_id_to_path 这里是来自Xcodedebugging控制台的photoIdToPath字典内容分析: (lldb) po photoIdToPath { 417675729 = "/Users/k06a/Library/Application Support/iPhone Simulator/7.1/Applications/21163736-DF6F-4E79-8196-6A966C81ED1B/Documents/417675729"; } (lldb) po [[[photoIdToPath allKeys] lastObject] class] __NSCFNumber (lldb) po [[[photoIdToPath allValues] lastObject] class] NSPathStore2 所以NSPathStore2是NSString子类,为什么这个字典不是属性列表? 更新: 这里https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/nsuserdefaults_Class/Reference/Reference.html#//apple_ref/occ/instm/NSUserDefaults/setObject:forKey :我发现文字: […]