Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 16th, 2012  |  syntax: None  |  size: 0.71 KB  |  hits: 11  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. // example load method
  2. - (NSArray *)loadData {
  3.         NSString *filePath = [[NSBundle mainBundle] pathForResource:@"cities1000" ofType:@"txt"];
  4.        
  5.         // Load the contents of the file into memory
  6.         NSError *err = nil;
  7.         NSString *contents = [NSString stringWithContentsOfFile:filePath
  8.                                                                                                    encoding:NSUTF8StringEncoding
  9.                                                                                                           error:&err];
  10.         if (err != nil) {
  11.                 // Something went wrong
  12.                 NSLog(@"Error reading failed banks text file: %@", [err localizedDescription]);
  13.                 return nil;
  14.         }
  15.        
  16.         // convert the content into an array of each line
  17.         NSArray *lines = [contents componentsSeparatedByString:@"\n"];
  18.     //NSArray *lines = [contents componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];
  19.         return lines;
  20. }