Tag: nsdictionary

iOS / Swift 1.2 NSDictionray / Dictionary上的NSStandardUserDefaults

在“旧”Swift中,我用来注册我的默认值从.plist文件加载,像这样… let prefs = NSBundle.mainBundle().pathForResource("UserDefaults", ofType: "plist"); let dict = NSDictionary(contentsOfFile: prefs!); let defaults:NSDictionary! = dict?.valueForKey("defaults") as! NSDictionary; NSUserDefaults.standardUserDefaults().registerDefaults(defaults); NSUserDefaults.standardUserDefaults().synchronize(); 在Swift 1.2下,我得到错误… 无法使用types为“(NSDictionary!)”的参数列表调用“registerDefaults” 所以,事情已经改变了,Swift不再接受一个NSDictionary作为registerDefaults的一个参数。 那么,如何将我的NSDictionary转换为一个Dictionary对象,因为它们不能再互换?

将NSArray与NSDate对象按月分类到NSDictionary中

我正在构build一个UITableView并希望按月分组,以便我可以将这些string作为我的部分标题,例如: February 2013 – Item 1 – Item 2 January 2013 – Item 1 – Item 2 我有一个NSArray具有一个NSDate pubDate属性的自定义对象。 我如何使用NSDate对象按月将我的自定义对象分组到一个NSDictionary ?

从iOS中快速删除字典中的值

我有一个JSON对象,如下所示: The Result { shops = ({ date = "2015-07-22T14:14:48.867618"; "num_items" = 0; score = "-1"; "total_spend" = 0; }, { date = "2015-07-22T14:17:03.713194"; "num_items" = 1; score = 5; "total_spend" = "1.85"; }); } 和我的代码: let dict = result as! NSDictionary var mutDict: NSMutableDictionary = dict.mutableCopy() as! NSMutableDictionary for (key, value) in mutDict { […]

从parse.com获取objectId

所以我正在构build一个使用parsing作为后端的应用程序。 我已经写了我自己的,但我想我会节省一些时间,并使用parsing。 我用parsing的数据填充表视图,这很好。 我想抓取从parsing数组构build的字典中的objectId。 我的数组的输出如下所示: <news_events:pdbIEvOteH:(null)> {\n eventDescription = \"This is a test description.\";\n eventMessage = \"This is a test message.\";\n eventTitle = \"Free Wi-Fi Now Available!\";\n} 在上面的例子中,对象ID是pdbIEvOteH 。 我起初试图通过使用获取id: NSString * objectId = [myDictionary objectForKey:@"objectId"]; 但是,返回null。 我知道这是不是我的字典问题,因为我可以得到其他信息。 问题是它看起来像上面的数组中没有关键的objectId 。 正如你可以看到它遵循news_events 。 我知道你可以用PFObject得到它,但我不确定是否可以用PFObject填充表。 所以底线是如何获得objectId 。

iOS objective-c – JSONstring到NSDictionaryexception

我对Objective-C比较陌生,并且在MapKit(位于这里 )的介绍中学习了一个教程。 我一直在试图debugging传递给NSDictionary的JSONstring的问题。 我收到以下错误: 2012-08-13 11:18:30.370 ArrestsPlotter[76578:c07] -[__NSCFString JSONValue]: unrecognized selector sent to instance 0x73a6400 2012-08-13 11:18:30.372 ArrestsPlotter[76578:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString JSONValue]: unrecognized selector sent to instance 0x73a6400' *** First throw call stack: (0x17b4022 0x131bcd6 0x17b5cbd 0x171aed0 0x171acb2 0x34782 0x35351 0x1c65e 0x17b5e42 0xda49df 0x178894f 0x16ebb43 0x16eb424 0x16ead84 0x16eac9b […]

– :对象的数量(0)不同于键的数量(2)

我得到的错误 – [NSDictionary initWithObjects:forKeys:]:对象的数量(0)不同于键的数量(2)' 这是我的代码保存plist。 @interface setting : UIViewController{ UIDatePicker *datePicker; IBOutlet UILabel * morningtime; UIDatePicker *afternoonpicker; NSString*morningtime1; NSString*afternoontime1; IBOutlet UILabel *afternoontime; } @property (nonatomic,retain) IBOutlet UIDatePicker *datePicker; @property (strong, nonatomic) IBOutlet UIDatePicker *afternoonpicker; @property (nonatomic, retain) IBOutlet NSString *morningtime1; @property (nonatomic, retain) IBOutlet NSString *afternoontime1; @property (nonatomic, retain) IBOutlet UILabel *morningtime; @property (nonatomic, retain) […]

将NSArray转换为JSON对象数组

我想从结果数组中创build一个JSON数组对象。 NSMutableArray *resultsArray = [NSMutableArray array]; FMResultSet *resultsSet = [database executeQuery:queryString]; while ([resultsSet next]) { [resultsArray addObject:[resultsSet resultDictionary]]; } 为了澄清,我使用FMDB查询数据库。 然后,我将结果对象存储在resultsArray中。 从这里我想将结果数组转换成JSON数组对象。

是否有保存NSDictionary文件的限制

我想用下面的方法来保存NSDictionary + (void)writeDicToFile:(NSDictionary *)dic fileName:(NSString *)fileName { NSString *filePath = [NSTemporaryDirectory() stringByAppendingPathComponent:fileName]; [dic writeToFile:filePath atomically:YES]; } 但是,对于一些字典,它的工作原理和一些复杂的字典是行不通的。 帮我!

NSDictionary描述不返回utf8字符?

我有一个NSDictionary与utf8string作为对象。 打印对象时,应打印特殊字符。 但是,当我使用description方法将字典转换为string时,utf8字符无法正确打印出来。 NSDictionary *test = [NSDictionary dictionaryWithObject:@"Céline Dion" forKey:@"bla"]; NSLog(@"%@",[test objectForKey:@"bla"]); // prints fine NSLog(@"%@",test); // does not print fine, é is replaced by \U00e NSLog(@"%@",[test description]); // also does not print fine 如何在保留utf8字符的同时打印NSDictionary?

如何从NSDictionary获取键/值对?

我需要一点NSDictionary的帮助。 我怎么能得到1对,如果我有字典,可以说“id”的值 NSDictionary *allCourses = [NSJSONSerialization JSONObjectWithData:allCoursesData options:NSJSONReadingMutableContainers error:&error]; 它看起来像这样: 谢谢你的帮助。