
Untitled
By: a guest on
Apr 16th, 2012 | syntax:
None | size: 0.71 KB | hits: 11 | expires: Never
// example load method
- (NSArray *)loadData {
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"cities1000" ofType:@"txt"];
// Load the contents of the file into memory
NSError *err = nil;
NSString *contents = [NSString stringWithContentsOfFile:filePath
encoding:NSUTF8StringEncoding
error:&err];
if (err != nil) {
// Something went wrong
NSLog(@"Error reading failed banks text file: %@", [err localizedDescription]);
return nil;
}
// convert the content into an array of each line
NSArray *lines = [contents componentsSeparatedByString:@"\n"];
//NSArray *lines = [contents componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];
return lines;
}