1

Hello Everyone, I haven't been able to figure our why my .txt file shows up fine on my simulators but not my iphone.

I found info about .png's doing the same thing but because of a compiling issue.

My build throws no errors and the section headers and correct cell quantities appear but no text.

This is the code I am using to extract the array of data from the .txt files.

So is there a better way of extracting the data from a .txt file into an array? Or is there a compiling issue like the .png? Or am I a dummy and I should know this isn't the correct way of creating an array from a .txt file?

NSString *delimiter = @"\n";
    /*
     Pull contents of text file, convert to string format, separate by newline, finish by giving new local array a pointer
    */
    //COWEL DOOR CHECK
    NSData *cowelDoorCheckTF = [NSData dataWithContentsOfFile:@"/Users/Makey/Dropbox/iPreFlight/iPreFlight R22/Text Data Files/PreFlight/CowelDoorCheck.txt"];
    NSString *cowelDoorCheckString = [[NSString alloc]initWithBytes:[cowelDoorCheckTF bytes] length:[cowelDoorCheckTF length] encoding:NSUTF8StringEncoding];
    NSArray *cowelDoorCheck = [cowelDoorCheckString componentsSeparatedByString:delimiter];
AMIC MING
  • 6,306
  • 6
  • 46
  • 62
Mak
  • 11
  • 1

2 Answers2

2

Your txt file should exist as a resource in your app, not a file in some other directory on your computer. Otherwise it won't exist as part of your app.

See the physical path for my files inside the Resources folder of XCode (for IOS) for a starting point. The first answer for iOS - how to read entire content of an html resource file into an NSString *? also provides a usage example

Community
  • 1
  • 1
Krease
  • 15,805
  • 8
  • 54
  • 86
  • Thank you... although I'll have to figure out how to do that now.. any good threads you can point me to? – Mak Jan 10 '13 at 19:26
  • See edit - should provide good starting point for the functions you'll want to use. – Krease Jan 10 '13 at 19:27
1

Check the case of the filename. File names are case-insensitive in the simulator, but are case-sensitive on the device.

So, for example, if the resource's actual filename is "FOO.txt", but your code loads it as "foo.txt", then it will work in the simulator but not on the device.

Kristopher Johnson
  • 81,409
  • 55
  • 245
  • 302