NSArray category
Each method in the NSArray category corresponds to a method in the NSArray class, but provides a secure version of the functionality. For more information about the functionality and usage, see NSArray 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 NSArray.
Method in category |
Corresponding method in NSArray |
|
|
|
|
|
|
|
|
|
|
|
|
Example:
The following example shows how to use NSArray and NSMutableArray category methods to:
1. | Create a secure file and write data to it from a NSMutableArray object. |
2. | Read the contents of the secure file into an NSArray object. |
For brevity, the example does not include error handling.
- (void)NSArrayCategoryExample { NSError *error; // Create an array and populate it. NSArray *array = [NSArray arrayWithObjects:@"one fish", @"two fish", @"red fish", @"blue fish", nil]; // Write the array to a secure file. NSString *secureArrayFileName = @"/tmp/secureArray"; [array writeToSecureFile:secureArrayFileName atomically:TRUE error:&error]; // Create an array from the contents of the secure file. NSArray *arrayCopy = [[NSArray alloc] initWithContentsOfSecureFile:secureArrayFileName error:&error]; // The contents of the objects 'array' and 'arrayCopy' are identical. }