nsdictionary

iOS - Add NSDictinary key values into an NSArray sequencialy

我是研究僧i 提交于 2020-01-05 21:09:32
问题 I have a NSDictionary and a NSArray : self.dataDic = [[[NSDictionary alloc] init] autorelease]; self.dataDicKey = [[[NSArray alloc] init] autorelease]; These are the key and value of my NSDictionary : self.dataDic = @{@"Ring Cloud" :@[@"Contact Cloud", @"Image Cloud", @"Data Cloud"], @"Ring Tools" :@[@"Sticker Market", @"Live Poll", @"Mail"], @"Ring Apps" :@[@"Studio", @"Player"]}; Now what I want is to insert all the key value of my self.dataDic into self.dataDicKey sequentially. That means

ObjectForKey always returning null or 0 when I know the value to be 1

时光毁灭记忆、已成空白 提交于 2020-01-05 08:51:17
问题 I've made a call to retrieve a user's active permissions using self.permissionRequest = [facebook requestWithGraphPath:@"me/permissions" andDelegate:self]; (I set the FBRequest object so I can identify it in the delegate method) In the delegate I call: if (request == self.permissionRequest) { DLog(@"Result: %@", result); } And I get a nice print out of active permissions: Result: { data = ( { bookmarked = 1; "create_note" = 1; email = 1; installed = 1; "photo_upload" = 1; "publish_stream" = 1

Is it possible to observe the count of an NSDictionary using KVO?

不羁岁月 提交于 2020-01-05 07:56:05
问题 I want to be set the badge value of a UITabItem based on the count of an NSDictionary. I'd like to do this without too much code. KVO seems the way to go, but I can't seem to find anything on simply observing the count of the dictionary, which makes me suspect this is not possible. So, my question: is it possible to observe the count of an NSDictionary using KVO? 回答1: Wrap the dictionary in another object (a proxy) that has a count property that you can observe. You could be all fancy (at the

Not all keys work when converting JSON String to NSDictionary

感情迁移 提交于 2020-01-04 07:00:32
问题 I'm using the following code to convert a JSON string literal to an array holding an NSDictionary for each item: NSString* json = @"[{\"name\":\"Item 1\",\"id\":\"999\",\"lang\":\"en\",\"type\":\"A\",\"version\":15}]"; NSData* data = [json dataUsingEncoding:NSUTF8StringEncoding]; NSArray* values = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil]; After removing the app from my test device, the app started crashing when attempting to access, in a

How to load an NSDictionary from a file created with writeToFile?

可紊 提交于 2020-01-04 03:01:16
问题 I have an NSMutableDictionary, and I wrote it using [stuff writeToFile:@"TEST" atomically:YES]; How can I retrieve it in the future? Also, what would happen if I decide to replace my iPhone 4 with the 4S? Can my piece of written data be transferred? 回答1: I think you want something like: [[NSMutableDictionary alloc] initWithContentsofFile:[self dataFilePath]]; You do need to obtain the correct path to store and retrieve your file, along the lines of this routine: - (NSString *)dataFilePath {

best way to load an image library of iphone nsmutablearray (600+ items)

偶尔善良 提交于 2020-01-03 06:27:29
问题 I have created an app which has a library of images. I have imported the images in to my resources folder in Xcode and am currently loading them in to an array in the appDelegate when the app loads. This is happening each time. I am now worried that as the library grows the app will run out of memory. Is there a better way of loading these? the structure is Library > category > image list > image I have an NSMutableArray called mainLibrary which I then add another nsmutablearray for each

how to use NSDictionary in NSUserDefault?

余生长醉 提交于 2020-01-03 05:02:54
问题 I want to know how can I use NSDictionary in NSUserDefault ? I have to store name, points and time of user into the NSDictionary and dictionary into the user default. 回答1: NSDictionary *dict = [[NSDictionary alloc] init]; [[NSUserDefaults standardUserDefaults] setObject:dict forKey:@"dict"]; [[NSUserDefaults standardUserDefaults] synchronize]; At the time of retrieval of data, dict = [[NSUserDefaults standardUserDefaults] objectForKey:@"dict"]; 回答2: NSUserDefaults *defaults = [NSUserDefaults

JSON format: getting output in the correct order [duplicate]

。_饼干妹妹 提交于 2020-01-03 03:16:10
问题 This question already has an answer here : Keeping dictionary keys of JSON Object in order in Objective C (1 answer) Closed 5 years ago . Common task, converting strings to a JSON format. Yes, easy, plenty of answers on StackOverflow about this. What is not as easy is to understand for me is why the order I get is different from the order I put the pair objects in the NSDictionary. That's the code I wrote: -(NSString*)createJSONstring { //http://www.raywenderlich.com/5492/working-with-json-in

remove duplicate valuse from NSMutable array [duplicate]

十年热恋 提交于 2020-01-02 08:50:32
问题 This question already has answers here : The best way to remove duplicate values from NSMutableArray in Objective-C? (14 answers) How to compare and merge NSMutableArray (2 answers) Closed 6 years ago . I am trying to remove any duplicates from my sorted array... I thought I could do it using an example from another question of mine but it turns out to not even come close to working. its a pretty horrible attempt, but its the only way i can figure out how to compare two elements of a single

NSDictionary's allKeys array messed up - not in the order they are in the dictionary?

☆樱花仙子☆ 提交于 2020-01-02 04:11:43
问题 in my project I'm pulling data from a .plist, more concretely from an NSDictionary. I init a dictionary with the contents of the .plist, which works well. When I then do NSArray *array = [dict allKeys]; it fills the array with all the keys, but in a totally random order, different to the order they are in the .plist file. I would really need to preserve the order. The keys in the dictionary are arrays, if that could cause a problem. What am I not getting? Thanks a lot in advance! 回答1: Much