nsdictionary

How to convert NSManagedObject to NSDictionary

大城市里の小女人 提交于 2019-11-29 13:44:10
问题 I am trying to convert NSManagedObject to NSDictionary this is what I tried: var keys:NSArray = order?.entity.attributesByName.keys var dict:NSDictionary = order?.dictionaryWithValuesForKeys(keys) But I get error: LazyForwardCollection<MapCollectionView<Dictionary<NSObject, AnyObject>, NSObject>>? is not convertible to NSArray. What am I doing wrong here? 回答1: The keys property of a dictionary returns a LazyForwardCollection which has to be converted to a real array. Another problem is that

Reading plist file

蓝咒 提交于 2019-11-29 13:33:20
问题 I created plist with big base of different animals in it (keys) and added this plist in my project. Type of every animal is NSDictionary. In every dictionary there are 5 more keys - characteristics of these animals (). I would like to go through every animal and if I match a certain characteristics of this animal, I put this animal in another array. So, I tried to make a code: NSArray *newArray = [[NSArray alloc]initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"animals" ofType:@

NSDictionary value replacing instead of adding in Plist

孤人 提交于 2019-11-29 12:12:05
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; userNotesTextview.text=@""; [self savingMetaData]; NSMutableArray *notes=[[NSMutableArray alloc]init]

NSDictionary with NSNumber to NSString mapping is non-property-list object

佐手、 提交于 2019-11-29 12:10:18
Following code: [[NSUserDefaults standardUserDefaults] setObject:photoIdToPath forKey:@"photo_id_to_path"]; gives me the following error: Attempt to set a non-property-list object { 417675729 = "/Users/k06a/Library/Application Support/iPhone Simulator/7.1/Applications/21163736-DF6F-4E79-8196-6A966C81ED1B/Documents/417675729"; } as an NSUserDefaults value for key photo_id_to_path Here is photoIdToPath dictionary content analysis from Xcode debug console: (lldb) po photoIdToPath { 417675729 = "/Users/k06a/Library/Application Support/iPhone Simulator/7.1/Applications/21163736-DF6F-4E79-8196

NSDictionary: method only defined for abstract class. My app crashed

≯℡__Kan透↙ 提交于 2019-11-29 11:03:43
问题 My app crashed after I called addImageToQueue. I added initWithObjects: forKeys: count: but it doesn't helped me. Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSDictionary initWithObjects:forKeys:count:]: method only defined for abstract class. Define -[DictionaryWithTag initWithObjects:forKeys:count:]!' my code - (void)addImageToQueue:(NSDictionary *)dict { DictionaryWithTag *dictTag = [DictionaryWithTag dictionaryWithDictionary:dict]; } @interface

NSMutableDictionary is adding quotes to keys and values - why?

穿精又带淫゛_ 提交于 2019-11-29 11:02:25
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" = "/images/mpsL/11727.jpeg"; majority = 3460; Both keys and values are NSStrings, with no quotes - so I'm

Grouping NSArray of NSDictionary based on a key in NSDictionay

坚强是说给别人听的谎言 提交于 2019-11-29 10:39:51
I am trying to filter out a NSArray of NSDictionaries. With my below example, I want dict1, dict2 & dict4 grouped in one array, dict3 & dict5 grouped in second array and dict6 in third array. I am getting this data in NSArray, so essentially the "orig" array below is my input and I know that I need to do grouping based on "Name" key. Instead of looping through the NSArray I though of using valueForKeyPath to return me array based on the key path but this does not work (crashes with logs -[NSMutableArray addObjectsFromArray:]: array argument is not an NSArray'). Any suggestion. NSDictionary

How to create an NSDictionary with multiple keys?

泪湿孤枕 提交于 2019-11-29 10:26:14
问题 I am not sure if what I am going to ask is actually an NSDictionary with multiple keys but ok. What I want to do is create an NSDictionary with keys and values for my data and then convert it to JSON format. The JSON format would look exactly like this : { "eventData": { "eventDate": "Jun 13, 2012 12:00:00 AM", "eventLocation": { "latitude": 43.93838383, "longitude": -3.46 }, "text": "hjhj", "imageData": "raw data", "imageFormat": "JPEG", "expirationTime": 1339538400000 }, "type":

Check if key exists in NSDictionary is null or not

烂漫一生 提交于 2019-11-29 09:18:14
I did search on how to check if NSDictionary key exists or not and came up with the solution. But still it throws me an error saying adding null value to the key. I am not sure if my code is correct or not. If anyone has any idea about this can help me. NSDictionary *result; id myImageURL = [result objectForKey:@"url"]; if ((NSNull *)myImageURL == [NSNull null]) myImageURL = @""; id myImage = [result objectForKey:@"image"]; if ((NSNull *)myImage == [NSNull null]) myImage = @""; Check if null add nothing and if not add the value. But it still gives me an error dont know why. /****OUTPUT*****/

UIPickerView with NSDictionary

孤街醉人 提交于 2019-11-29 09:02:59
问题 I am a .NET programmer and new to Objective C. I am trying to make a UIPickerView which acts like a .NET dropdownlist. User sees the list of text and selects one and the selected value (which is the ID) is used in code. I have been browsing for almost half a day trying to figure this out. I could add a regular PickerView with list of strings, picker view with mulitple components and picker view with dependent components none of which seems to answer my query. Please help. 回答1: You can use a