nsdictionary

NSPredicate on array of arrays

大城市里の小女人 提交于 2019-11-29 07:59:13
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 ~80mb to ~120mb), so if possible I would to keep the array. Any suggestions on how this might be done

How to Read Plist without using NSDictionary in Swift?

╄→尐↘猪︶ㄣ 提交于 2019-11-29 07:42:31
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) 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 PropertyListSerialization.propertyList(from: data, format: nil) as! [String:Any] // do something with the

How to sort a NSArray which contains NSDictionary?

自作多情 提交于 2019-11-29 07:39:18
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</string> </dict> </array> </dict> </plist> Now I want to sort this by the highscoreInSeconds . NSArray

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

孤者浪人 提交于 2019-11-29 07:34:22
This question already has an answer here: NSMutableDictionary is adding quotes to keys and values - why? 2 answers 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 = [NSMutableDictionary dictionaryWithObjectsAndKeys: numberOfPhotosAsString, @"PackageFileCount", wtID, @"wtID", uploadType, @"type"

Retrieving values from json using objective-c

一个人想着一个人 提交于 2019-11-29 04:07:18
问题 I am currently trying to work with json and objective-c however having a bit of difficulty. The following is the json that is being returned { sethostname = ( { msgs = "Updating Apache configuration\nUpdating cPanel license...Done. Update succeeded.\nBuilding global cache for cpanel...Done"; status = 1; statusmsg = "Hostname Changed to: a.host.name.com"; warns = ( ); }); } I am able to check that the response is coming back and the key is sethostname however no matter what I try I cannot get

Why is NSUserDefaults unwilling to save my NSDictionary?

白昼怎懂夜的黑 提交于 2019-11-29 03:41:55
I'm using KVC to serialize an NSObject and attempt to save it to NSUserDefaults , which is giving me an Attempt to insert non-property value when I try to store my NSDictionary . Following are the properties of the object in question, MyClass : @interface MyClass : NSObject @property (copy,nonatomic) NSNumber* value1; @property (copy,nonatomic) NSNumber* value2; @property (copy,nonatomic) NSString* value3; @property (copy,nonatomic) NSString* value4; @property (copy,nonatomic) NSString* value5; @property (copy,nonatomic) NSString* value6; @property (copy,nonatomic) NSString* value7; @property

How to sort an array of dates in descending order

早过忘川 提交于 2019-11-29 03:25:06
I have a NSDictionary that parsed to an array one of the element is date, i tried using [startimeArray sortUsingSelector:@selector(compare:)]; (starttimeArray) is my date but it only arrange ascending. how can i sort in descending order. thanks Sort the array by puting NO is ascending parameter: NSSortDescriptor *descriptor=[[NSSortDescriptor alloc] initWithKey:@"self" ascending:NO]; NSArray *descriptors=[NSArray arrayWithObject: descriptor]; NSArray *reverseOrder=[dateArray sortedArrayUsingDescriptors:descriptors]; vikingosegundo You can use a comparator block NSArray *sortedArray = [array

Casting a CFDictionaryRef to NSDictionary?

一个人想着一个人 提交于 2019-11-29 02:49:09
I have the code (stripped down): CFDictionaryRef *currentListingRef; //declare currentListingRef here NSDictionary *currentListing; currentListing = (NSDictionary *) currentListingRef; And then I get the error: Cast of a non-Objective-C pointer type 'CFDictionaryRef *' (aka 'const struct __CFDictionary **') to 'NSDictionary *' is disallowed with ARC What am I doing wrong? How do I convert from a CFDictionaryRef to an NSDictionary ? ARC changed the way bridging works. NSDictionary *original = [NSDictionary dictionaryWithObject:@"World" forKey:@"Hello"]; CFDictionaryRef dict = (__bridge

Weak object in an NSDictionary?

杀马特。学长 韩版系。学妹 提交于 2019-11-29 02:48:53
问题 I would like to store a zeroing weak reference to an object in a NSDictionary . This is for a reference to a parent NSDictionary , so I can crawl back up a large structure without searching. I can not use __weak here; even if my local reference is weak, the NSDictionary will store a strong reference to the object that was weakly referenced. And, of course, NSDictionary can't have nil objects. I'm on iOS, not Mac, so NSHashTable isn't available. And I only want one object to be weak; the rest

iOS: Why can't I set nil to NSDictionary value?

匆匆过客 提交于 2019-11-29 02:06:43
问题 This might be very basic question but I was wondering why can't I assign nil as NSDictionary value? I have following statement many places in my code. If [q objectForKey:@"text"] is nil then App is crashing. NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithCapacity:2]; [dict setObject:[q objectForKey:@"text"] forKey:@"text"]; I have to check everywhere for the nil before assigning it to dictionary. Is this the only correct way of doing? Am I missing something obvious? if([q