nsdictionary

Check if NSDictionary is empty

天涯浪子 提交于 2019-12-21 03:38:08
问题 I want to check if an NSDictionary is empty. I am doing it like this. mutDictValues = [[[NSUserDefaults standardUserDefaults] objectForKey:@"dicValues"]mutableCopy]; NSLog(@"dictValues are %@",mutDictValues); if(mutDictValues == NULL){ arrCities = [[NSMutableArray alloc]init]; NSLog(@"no cities seleceted"); }else{ arrCities = [[NSMutableArray alloc]init]; arrCities = [mutDictValues objectForKey:@"cities"]; [self placeCities]; } But it alwasy crashes on this line arrCities = [mutDictValues

UIView as dictionary key?

雨燕双飞 提交于 2019-12-21 03:25:15
问题 I want to have a NSDictionary that maps from UIView s to something else. However, since UIViews do not implement the NSCopying protocol, I can't use them directly as dictionary keys. 回答1: You can use an NSValue holding the pointer to the UIView and use this as key. NSValues are copyable. but, if the view is destroyed, the NSValue will hold a junk pointer. 回答2: Here is the actual code (based on the answer by luvieere and further suggestion by Yar): // create dictionary NSMutableDictionary*

Populate tableview from NSDictionary

一个人想着一个人 提交于 2019-12-21 02:56:42
问题 I have an NSDictionary received from a json request that looks like this: RESULT : ( { Id1 = 138; lat = "45.5292910"; long = "-73.6241500"; order = "2343YY3" }, { Id1 = 137; lat = "45.5292910"; long = "-73.6241500"; order = "2343YY3" }, etc. I want to display it in a TableView (CellforRowAtIndexPath), so I obtain the data as NSArray. The method seems inefficient as each key Id1 , lat , long , etc is created as an NSArray so that I can display them each with: [self.data1 objectAtIndex

NSDictionary setValue:forKey: — getting “this class is not key value coding-compliant for the key”

♀尐吖头ヾ 提交于 2019-12-20 17:39:52
问题 I have this simple loop in my program: for (Element *e in items) { NSDictionary *article = [[NSDictionary alloc] init]; NSLog([[e selectElement: @"title"] contentsText]); [article setValue: [[e selectElement: @"title"] contentsText] forKey: @"Title"]; [self.articles insertObject: article atIndex: [self.articles count]]; [article release]; } It is using the ElementParser library to make a dictionary of values from an RSS feed (there are other values besides "title" which I have omitted). self

AFNetworking 2.0 - use responseObject as NSDictionary

霸气de小男生 提交于 2019-12-20 10:33:09
问题 AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; [manager GET:@"http://example.com/resources.json" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) { NSLog(@"JSON: %@", responseObject); } failure:^(AFHTTPRequestOperation *operation, NSError *error) { NSLog(@"Error: %@", error); }]; this is the recommended way to send GET request in AFNetworking 2.0. I want to get the value of a specific key in the json, so I want to use

NSDictionary sort by keys as floats

为君一笑 提交于 2019-12-20 09:59:46
问题 basically I have an NSDictionary with keys and values. The keys are all numbers, but at the moment they are strings. I want to be able to compare them as numbers in order to sort them. eg: If I have a Dictionary like this: { "100" => (id)object, "20" => (id)object, "10" => (id)object, "1000" => (id)object, } I want to be able to sort it like this: { "10" => (id)object, "20" => (id)object, "100" => (id)object, "1000" => (id)object, } Any ideas? Thanks Tom 回答1: Not sure what you are up to –

Inserting nil objects into an NSDictionary

99封情书 提交于 2019-12-20 08:49:40
问题 If we have an API that requires only 2 out of an objects 5 properties and iPhone app doesn't require them to instantiate an object, when the object is used in the params NSDicitionary the app will crash. I was told NSDictionary will not let you assign nil values, as when it reaches nil it thinks its finished. Does objective-c have a way to spit out an objects non-nil properties into an NSDictionary? Example: [Drunk alloc] init]; drunk.started_drinking = [NSDate date]; drunk.stopped_drinking

Trying to encrypt an NSDictionary when writing to file

柔情痞子 提交于 2019-12-20 08:29:21
问题 I'm currently saving an NSDictionary to file on the iOS device. However, NSDictionary files are readable XML. I don't want people to be able to get in and read the contents so I need to be able to encrypt the file on writing and decrypt when loading it back again. I'm currently saving the file like this: NSFileManager* fileManager = [NSFileManager defaultManager]; if (!fileManager) { NSLog(@"Failed to get file manager to save."); return; } NSArray* paths = NSSearchPathForDirectoriesInDomains

Instantiating Custom Class from NSDictionary

无人久伴 提交于 2019-12-20 08:19:04
问题 I have a feeling that this is stupid question, but I'll ask anyway... I have a collection of NSDictionary objects whose key/value pairs correspond to a custom class I've created, call it MyClass . Is there an easy or "best practice" method for me to basically do something like MyClass * instance = [ map NSDictionary properties to MyClass ]; ? I have a feeling I need to do something with NSCoding or NSKeyedUnarchiver , but rather than stumble through it on my own, I figure someone out there

Swift: looping into array of dictionaries (Error: Any is not convertible to NSDictionary)

吃可爱长大的小学妹 提交于 2019-12-20 07:44:15
问题 I'm trying to run for loop in an Array of dictionaries. But I'm getting this error: Any is not convertible to NSDictionary Here is my implementation: let content:NSArray = json .object(forKey: "books") as! NSArray for contentDic:NSDictionary in content { print(contentDic) } How can I cast contentDic to Dictionary or NSDictionary without having this error? I'll really appreciate your help. 回答1: If you can guarantee that your content is an array of NSDictionary , you can: for contentDic