nsdictionary

NSMutableDictionary is adding quotes to keys and values - why?

二次信任 提交于 2019-11-28 04:19:57
问题 I'm trying to add some additional key/value pairs to an NSMutableDictionary, using: Tag *tag1 = [results1 objectAtIndex:0]; [resultsDict setObject:[tag1 retrieveTextUpToDepth:1] forKey:@"image_url"]; Tag *tag2 = [results2 objectAtIndex:0]; [resultsDict setValue:[tag2 retrieveTextUpToDepth:1] forKey:@"majority"]; This adds the k/v pairs with no problem, except when I come to retrieve them, some of the values have been wrapped with double quotes: po extendedDataDictionary: "image_url" = "

Obj-C easy method to convert from NSObject with properties to NSDictionary?

删除回忆录丶 提交于 2019-11-28 03:43:32
I ran across something that I eventually figured out, but think that there's probably a much more efficient way to accomplish it. I had an object (an NSObject which adopted the MKAnnotation protocol) that had a number of properties (title, subtitle,latitude,longitude, info, etc.). I needed to be able to pass this object to another object, which wanted to extract info from it using objectForKey methods, as an NSDictionary (because that's what it was getting from another view controller). What I ended up doing was create a new NSMutableDictionary and use setObject: forKey on it to transfer each

adding multiple entries to a HashMap at once in one statement

若如初见. 提交于 2019-11-28 02:52:05
I need to initialize a constant HashMap and would like to do it in one line statement. Avoiding sth like this: hashMap.put("One", new Integer(1)); // adding value into HashMap hashMap.put("Two", new Integer(2)); hashMap.put("Three", new Integer(3)); similar to this in objective C: [NSDictionary dictionaryWithObjectsAndKeys: @"w",[NSNumber numberWithInt:1], @"K",[NSNumber numberWithInt:2], @"e",[NSNumber numberWithInt:4], @"z",[NSNumber numberWithInt:5], @"l",[NSNumber numberWithInt:6], nil] I have not found any example that shows how to do this having looked at so many. You can do this: Map

NSPredicate on array of arrays

一个人想着一个人 提交于 2019-11-28 01:46:37
问题 I have an array, that when printed out looks like this: ( ( databaseVersion, 13 ), ( lockedSetId, 100 ) ) Would it be possible to filter this using an NSPredicate (potentially by the index in the array). So something like: give me all rows where element 0 is 'databaseVersion'? I know that if I had an array of dictionaries I could do this with a predicate similar the one found here, but I found that when using dictionaries and storing a large amount of data, my memory consumption went up (from

How to Read Plist without using NSDictionary in Swift?

99封情书 提交于 2019-11-28 01:26:59
问题 I've already used this method in Swift 2 var myDict: NSDictionary? if let path = NSBundle.mainBundle().pathForResource("Config", ofType: "plist") { myDict = NSDictionary(contentsOfFile: path) } But don't know how to read plist in Swift3 without using NSDictionary(contentsOfFile: path) 回答1: The native Swift way is to use PropertyListSerialization if let url = Bundle.main.url(forResource:"Config", withExtension: "plist") { do { let data = try Data(contentsOf:url) let swiftDictionary = try

How to sort a NSArray which contains NSDictionary?

拥有回忆 提交于 2019-11-28 01:08:47
问题 I have a plist like this: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>highscores</key> <array> <dict> <key>highscoreInSeconds</key> <string>9</string> <key>levelName</key> <string>1</string> <key>name</key> <string>Black</string> </dict> <dict> <key>highscoreInSeconds</key> <string>12</string> <key>levelName</key> <string>1</string> <key>name</key> <string>Black<

Why does string show up in NSDictionary with quotes, but others don't? [duplicate]

霸气de小男生 提交于 2019-11-28 01:07:34
问题 This question already has answers here : NSMutableDictionary is adding quotes to keys and values - why? (2 answers) Closed 6 years ago . So I have an NSMutableDictionary that I populate, but when I output the contents to NSLog, the key and value for the entries entered in the for loop show up differently, and the final NSLog call doesn't even output anything. What's going on here??? Please help! Why are the quotes around the entries added in the for loop??? NSMutableDictionary *params =

How do I load a plist file from disk as a NSDictionary on iOS?

三世轮回 提交于 2019-11-27 23:36:01
I want to load the plist file from disk (documents, application cache, ...) not from a resource bundle. You can load a plist from any accessible file path with -initWithContentsOfFile: or +dictionaryWithContentsOfFile: Load a plist from a file, and create the file if it did not exist: NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); self.plistFile = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"example.plist"]; self.plist = [[NSMutableDictionary alloc] initWithContentsOfFile:plistFile]; if (!plist) { self.plist = [NSMutableDictionary

Sorting NSDictionary

早过忘川 提交于 2019-11-27 22:29:44
I was wondering if someone can show me how to sort an NSDictionary ; I want to read it starting from the last entry, since the key is Date + Time and I want to be able to append it to an NSMutableString . I was able to read it using an enumerator but I don't get the results I want. Thanks For your requirements the easiest way is to create a new array from the keys, sort that, then use the array to reference items from the original dictionary. (Note myComparison is your own method that will compare two keys). NSMutableArray* tempArray = [NSMutableArray arrayWithArray:[myDict allKeys]];

What's the difference between a dictionary and an array?

混江龙づ霸主 提交于 2019-11-27 21:00:11
问题 What is the difference between a dictionary and an array, especially when working with PLIST files? What are the advantages of using one over the other? Thanks! 回答1: Both NSDictionary and NSArray are collection classes, i.e. the group together other objects. An NSArray is an 'ordered collection' - every item in the collection has an integer index, so there is an explicit order to the items. If you swap the order of items in the collection then the collection is no longer the 'same' as the