nsdictionary

Sort NSArray of NSDictionaries by string date in key?

懵懂的女人 提交于 2019-12-30 06:39:13
问题 I have been struggling to find an easy way to sort an NSMutableArray that contains NSDictionaries. Each NSDictionary has a key named "Date" which contains an NSString of a date (ex: 10/15/2014). What I am looking to do is sort the array based on those strings in ascending order. I have tried this with no luck: NSComparisonResult dateSort(NSString *s1, NSString *s2, void *context) { NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@"MM/dd/yy"]; NSDate *d1 =

With fast enumeration and an NSDictionary, iterating in the order of the keys is not guaranteed – how can I make it so it IS in order?

元气小坏坏 提交于 2019-12-30 04:00:10
问题 I'm communicating with an API that sends back an NSDictionary as a response with data my app needs (the data is basically a feed). This data is sorted by newest to oldest, with the newest items at the front of the NSDictionary. When I fast enumerate through them with for (NSString *key in articles) { ... } the order is seemingly random, and thus the order I operate on them isn't in order from newest to oldest, like I want it to be, but completely random instead. I've read up, and when using

Could not cast value of type '__NSDictionaryM' to 'NSArray" [duplicate]

人盡茶涼 提交于 2019-12-29 08:22:20
问题 This question already has answers here : Swift JSON error : Could not cast value of type '__NSDictionaryM' to 'NSArray' (3 answers) Closed 3 years ago . This is my part of my code: let quotesData = try NSJSONSerialization.JSONObjectWithData(data!, options: .MutableContainers) as! NSDictionary var quoteDictionary: [NSDictionary]! quoteDictionary = quotesData["response"] as! [NSDictionary] This is part of the JSON from the Tumblr API: { "meta": { "status": 200, "msg": "OK" }, "response": {

NSDictionary value replacing instead of adding in Plist

北城以北 提交于 2019-12-29 08:09:14
问题 hi i tried to add values(book id,page number,notes) from NSdictionary to Plist but each time the new value replacing the previous one?but i need all values in plist my code for adding dictionary to plist is NSString *bid=@"95"; NSString *pnum=@"12"; userNotes=[[NSMutableDictionary alloc]init]; [userNotes setValue:userNotesTextview.text forKey:@"notes"]; [userNotes setValue:bid forKey:@"bookid"]; [userNotes setValue:pnum forKey:@"pagenumber"]; userNotesView.hidden=YES; _background.hidden = YES

Convert NSDictionary to Swift Dictionary

天大地大妈咪最大 提交于 2019-12-29 03:50:28
问题 Now I know that when swift compiles it just makes a NSDictionary, but the NSDictionary and Swift dictionaries have different syntax. Is there a way (through a loop or something) to convert a NSDictionary to a swift dictionary of the same type for <key, value> ? OR Is there a way to convert this to a Swift dictionary instead of NSDictionary? let jsonDict = NSJSONSerialization.JSONObjectWithData(jsonData, options: nil, error: &error) as NSDictionary 回答1: use: let jsonDic = NSJSONSerialization

Filtering NSDictionary with predicate

陌路散爱 提交于 2019-12-29 03:21:08
问题 I am using a NSDictionary that itself contains dictionaries some keys and its values.The format is like , { "1" = { "key1" = "ss", "key2" = "rr", "name" = "nm" }, "2" = { "key1" = "tt", "key2" = "vv", "name" = "gf" }, "3" = { "key1" = "nm", "key2" = "vv", "name" = "gf" }, "4" = { "key1" = "tt", "key2" = "vv", "name" = "gf" }, } I need to filter with the case that key1 should be "tt" and key2 should "vv" using NSPredicate. 回答1: Assume that mainDict = { "1" = { "key1" = "ss", "key2" = "rr",

Is NSDictionary key order guaranteed the same as initialized if it never changes?

别等时光非礼了梦想. 提交于 2019-12-28 23:16:49
问题 I've run into the same problem as found in this question. However, I have a follow-up question. I seem to be in the same situation as the original asker: I have a plist with a hierarchy of dictionaries that define a configuration screen. These are not mutable and will stay the same throughout the application. Since the original discussion seems to focus on problems arising from mutating the dictionary, I must ask for comfirmation: is the order of a dictionary guaranteed the same as they are

Replace a value in NSDictionary in iPhone

心已入冬 提交于 2019-12-28 09:13:32
问题 I have a array (dataArray) of NSDictionary "item". It has datas like "david" for key "name" and "85" for key "marks" etc for 5 students. I want to replace the mark of david to 90 with respect to the array index value (ie 0 for dictionary containing david and 85). How can I do it? The code for content in array is [item setobject:name forkey:@"Name"]; [item setobject:mark forkey:@"Marks"]; [dataArray addOject:item] The above code goes inside parsing, so i have array with 5 objects (students),

File with string in JSON format , how to read filecontent into NSDictionary

左心房为你撑大大i 提交于 2019-12-26 09:59:49
问题 I have a file-"xyz.txt" in my applicaion bundle with just JSON formatted text. I want to open the filepath of the text file and read the content to NSDictionary. How to do that. I already have my JSON string ready. Just need to initliaze to NSdictionary. If I directly initilize in code , i would need lot of @ before evey key and value. and I want to avoid that. That is the reason , i put JSON in a file-"xyz.txt" I have two ways - 1.I read form file and assign it using [[NSDictionary alloc]

File with string in JSON format , how to read filecontent into NSDictionary

a 夏天 提交于 2019-12-26 09:58:10
问题 I have a file-"xyz.txt" in my applicaion bundle with just JSON formatted text. I want to open the filepath of the text file and read the content to NSDictionary. How to do that. I already have my JSON string ready. Just need to initliaze to NSdictionary. If I directly initilize in code , i would need lot of @ before evey key and value. and I want to avoid that. That is the reason , i put JSON in a file-"xyz.txt" I have two ways - 1.I read form file and assign it using [[NSDictionary alloc]