This:
NSMutableArray *directoryList;
defines a pointer to an array but doesn't create an instance. You should have:
NSMutableArray *directoryList = [NSMutableArray array];
so you have something to add the contents to.
Domanda
I am trying to concat two directory listings into one array, I get the directory arrays to show the list of files in each separately (NSLog), but concatenating them together via addObjectsFromArray, results in (null):
NSString *path1 = [NSHomeDirectory() stringByAppendingPathComponent:@"Desktop/Dir1/"];
NSString *path2 = [NSHomeDirectory() stringByAppendingPathComponent:@"Desktop/Dir2/"];
NSArray *directoryList1 = [[[NSFileManager defaultManager] contentsOfDirectoryAtPath:path1 error:nil]
pathsMatchingExtensions:[NSArray arrayWithObjects:@"log", nil]];
NSArray *directoryList2 = [[[NSFileManager defaultManager] contentsOfDirectoryAtPath:path2 error:nil]
pathsMatchingExtensions:[NSArray arrayWithObjects:@"log", nil]];
NSLog(@"directoryList1 contains: %@", directoryList1);
NSLog(@"directoryList2 contains: %@", directoryList2);
NSMutableArray *directoryList;
[directoryList addObjectsFromArray:directoryList1];
[directoryList addObjectsFromArray:directoryList2];
NSLog(@"directoryList contains: %@", directoryList);
Soluzione
This:
NSMutableArray *directoryList;
defines a pointer to an array but doesn't create an instance. You should have:
NSMutableArray *directoryList = [NSMutableArray array];
so you have something to add the contents to.