Replace a value in NSDictionary in iPhone

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!

Which method of checking to see if a NSDictionary contains a particular key is faster?

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

Serialize and Deserialize Objective-C objects into JSON

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: How to remove a null value from Dictionary?

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