NSDictionary category
Each method in the NSDictionary category corresponds to a method in the NSDictionary class, but provides a secure version of the functionality. For more information about the functionality and usage, see NSDictionary in developer.apple.com.
Note the following:
•The url parameter in the category methods must be a file URL, and point to a regular file.
•The category methods return an NSError object. The methods set the properties on the object as described in NSError objects that secure Objective-C methods return.
The following table shows each added method and its corresponding method in NSDictionary.
Method in category |
Corresponding method in NSDictionary |
|
|
|
|
|
|
|
|
|
|
|
|
Example:
The following example shows how to use NSDictionary and NSMutableDictionary category methods to:
1. | Create a secure file and write data to it from a NSMutableDictionary object. |
2. | Read the contents of the secure file into an NSDictionary object. |
For brevity, the example does not include error handling.
- (void)NSDictionaryCategoryExample { NSError *error; // Create and populate a dictionary. NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:@"baseball", @"white", @"basketball", @"orange", nil]; // Write the dictionary to a secure file. NSString *secureFileName = @"/tmp/secureDictionary"; [dict writeToSecureFile:secureFileName atomically:TRUE error:&error]; // Create a dictionary with the contents of the secure file. NSDictionary *dictCopy = [[NSDictionary alloc] initWithContentsOfSecureFile:secureFileName error:&error]; // Note: The contents of objects 'dict' and 'dictCopy' are identical. }