Friday, May 31, 2013

NSArray arrayWithContentsOfURL example in Objective C (iOS).

NSArray arrayWithContentsOfURL

Creates and returns an array containing the contents specified by a given URL.

+ (id)arrayWithContentsOfURL:(NSURL *)aURL

The location of a file containing a string representation of an array produced by the writeToURL:atomically: method.

Return Value
An array containing the contents specified by aURL. Returns nil if the location can’t be opened or if the contents of the location can’t be parsed into an array.

Discussion of [NSArray arrayWithContentsOfURL]
The array representation at the location identified by aURL must contain only property list objects (NSString, NSData, NSArray, or NSDictionary objects). The objects contained by this array are immutable, even if the array is mutable.

NSArray arrayWithContentsOfURL example.
NSMutableArray * mArray = [NSMutableArray arrayWithContentsOfURL:theNewURL];
[mArray removeObjectAtIndex:indexPath.row];

Example of [NSArray arrayWithContentsOfURL].
- (void)viewDidLoad
    [super viewDidLoad];
    if ([[NSFileManager defaultManager]fileExistsAtPath:[self pathToChosenStockTableData].path]){
         NSLog(@"URL:%@",[self pathToChosenStockTableData]);
        self.chosenStockArray = [NSArray arrayWithContentsOfURL:[self pathToChosenStockTableData]];

NSArray arrayWithContentsOfURL example.
        NSURL *url = [NSURL URLWithString:@""];
        NSArray *myArray = [NSArray arrayWithContentsOfURL:url];

End of NSArray arrayWithContentsOfURL example article.