Display each item in an NSDictionary
Try this code for(NSString *key in [dict allKeys]) { NSLog(@”%@”,[dict objectForKey:key]); }
Try this code for(NSString *key in [dict allKeys]) { NSLog(@”%@”,[dict objectForKey:key]); }
You should use a combination of arrays and dictionaries. Dictionaries are initialized like this: NSDictionary *dict = @{ key : value, key2 : value2}; Arrays are initialized like this: NSArray *array = @[Object1, Object2]
Here’s what you can do: NSMutableDictionary *newDict = [[NSMutableDictionary alloc] init]; NSDictionary *oldDict = (NSDictionary *)[dataArray objectAtIndex:0]; [newDict addEntriesFromDictionary:oldDict]; [newDict setObject:@”Don” forKey:@”Name”]; [dataArray replaceObjectAtIndex:0 withObject:newDict]; [newDict release]; Hope this helps!
A hash lookup should be faster in general than going over all the dictionary keys, creating an array from them (memory allocation is relatively expensive) and then searching the array (which can’t even be a binary search since the array is not sorted). For the sake of science, though, I made two executables that just … Read more
Finally we can solve this problem easily using JSONModel. This is the best method so far. JSONModel is a library that generically serialize/deserialize your object based on Class. You can even use non-nsobject based for property like int, short and float. It can also cater nested-complex JSON. Considering this JSON example: { “accounting” : [{ … Read more
Swift 5 Use compactMapValues: dictionary.compactMapValues { $0 } compactMapValues has been introduced in Swift 5. For more info see Swift proposal SE-0218. Example with dictionary let json = [ “FirstName”: “Anvar”, “LastName”: “Azizov”, “Website”: nil, “About”: nil, ] let result = json.compactMapValues { $0 } print(result) // [“FirstName”: “Anvar”, “LastName”: “Azizov”] Example including JSON parsing … Read more
NSArray * values = [dictionary allValues];