nsdictionary

NSPredicate on NSDictionary

╄→гoц情女王★ 提交于 2019-12-03 07:32:04
I'm trying to make sections in a table view based on the alphabet and sort my entries alphabetically under these sections. I have collected the first letter in every entry of bandsArray in bandsArrayIndex and I'm now trying to use NSPredicate to count how many of each letter there are. I'm doing this by following this guide . They are using an NSArray and I'm using an NSDictionary and can't seem to get it to work. Can anyone help me out? The application crashes when trying to show the view with the table view in it. In Debugger Console the following error is shown: * Terminating app due to

Passing data from local file using json

﹥>﹥吖頭↗ 提交于 2019-12-03 07:06:08
问题 I am trying to pass data to labels from my JSON file onto a simple ViewController but I don't know where to actually pass that data. Would I be able to just add to my setDataToJson method or would I add the data in my viewDidLoad method? here is my code @interface NSDictionary(JSONCategories) +(NSDictionary*)dictionaryWithContentsOfJSONString:(NSString*)fileLocation; @end @implementation NSDictionary(JSONCategories) +(NSDictionary*)dictionaryWithContentsOfJSONString:(NSString*)fileLocation{

Check key exists in NSDictionary

点点圈 提交于 2019-12-03 06:26:17
问题 how can I check if this exists?: [[dataArray objectAtIndex:indexPathSet.row] valueForKey:@"SetEntries"] I want to know whether this key exists or not. How can I do that? Thank you very much :) EDIT: dataArray has Objects in it. And these objects are NSDictionaries. 回答1: I presume that [dataArray objectAtIndex:indexPathSet.row] is returning an NSDictionary, in which case you can simply check the result of valueForKey against nil. For example: if ([[dataArray objectAtIndex:indexPathSet.row]

How can I store a UIImage in an NSDictionary?

纵饮孤独 提交于 2019-12-03 05:53:26
问题 How can I store a UIImage in an NSDictionary? 回答1: Yes you can: NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithCapacity:1]; UIImage *img = ...; [dict setObject:img forKey:@"aKeyForYourImage"]; UIImage *imgAgain = [dict objectForKey:@"aKeyForYourImage"]; 回答2: OK I had this problem recently and the above solutions never worked for me. So if someone else finds their way here to solve the same problem, here is how it's done NSDictionary *imageDictionary = @{ kImageKey:

How can I get all values for specific key from each NSDictionary in an NSArray? [duplicate]

▼魔方 西西 提交于 2019-12-03 05:42:01
问题 This question already has an answer here : How to get values from NSDictionaries inside an NSArray (1 answer) Closed 6 years ago . I have an array which contains dictionary objects. In each dictionary the key are common. Now I want to get all the values of that key. I have got these values with iteration, but I am looking for some straight forward way or a default method which does this job. Can you please help me to get one default method which serves the purpose? Thanks. Data Structure is

Create index for UITableView from an NSArray

别说谁变了你拦得住时间么 提交于 2019-12-03 04:35:11
问题 I've read that the best way of creating an index (the a-z at the side of a uitableview) is to set up an array of nsdictionaries, where each dictionary corresponds to a section, and a rowValue key contains an array of the rows. NSDictionary headerTitle => ‘A’ rowValues => {”Aardvark”, “Ape”, “Aquaman”} NSDictionary headerTitle => ‘B’ rowValues => {”Bat”, “Boot”, “Bubbles”} etc But how can this be created from an array of all the row titles - {”Aardvark”, “Ape”, “Aquaman”, ”Bat”, “Boot”,

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

天大地大妈咪最大 提交于 2019-12-03 04:34:20
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.articles is an NSMutableArray which is storing all of the dictionaries in the RSS document. In the end,

Storing NSManagedObject in a dictionary (NSDictionary)

喜夏-厌秋 提交于 2019-12-03 04:22:50
问题 I have a custom class, which is a subclass of NSManagedObject . I would like to store it in a dictionary, but when trying to do so I receive a Property list invalid for format: 200 error. Here is how I try to create the dictionary: NSDictionary *dictionary = [NSDictionary dictionaryWithObject: voiceMemo forKey:@"voiceMemo"]; Same result when trying NSDictionary *dictionary = [NSDictionary dictionaryWithObject: (NSData *) voiceMemo forKey:@"voiceMemo"]; It works, however, when trying to save

Sorting an NSArray by an NSDictionary value

余生长醉 提交于 2019-12-03 03:46:52
I'm trying to sort an array that would look something like this: (please ignore the fact these people are well past any living age! I just needed large numbers) NSDictionary *person1 = [NSDictionary dictionaryWithObjectsAndKeys:@"sam",@"name",@"28.00",@"age",nil]; NSDictionary *person2 = [NSDictionary dictionaryWithObjectsAndKeys:@"cody",@"name",@"100.00",@"age",nil]; NSDictionary *person3 = [NSDictionary dictionaryWithObjectsAndKeys:@"marvin",@"name",@"299.00",@"age",nil]; NSDictionary *person4 = [NSDictionary dictionaryWithObjectsAndKeys:@"billy",@"name",@"0.0",@"age",nil]; NSDictionary

Appending NSDictionary to other NSDictionary

拥有回忆 提交于 2019-12-03 03:27:51
问题 I have one NSDictionary and it loads up UITableView . If a user scrolls more and more, I call API and pull new data. This data is again in the form of an NSDictionary . Is it possible to add the new NSDictionary to the existing one? 回答1: You looking for this guy: [NSMutableDictionary addEntriesFromDictionary:] Make sure your UITableView dictionary is an NSMutableDictionary ! Check it here 回答2: Use NSMutableDictionary addEntriesFromDictionary to add the two dictionaries to a new mutable