Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

lynkynpark86

macrumors 6502
Original poster
Hello,
I am making an iPhone app to randomly pick a 6-digit ticket number from about 500 numbers. The app will be run in the simulator. It is for a technology-related contest, and the fact that I am using an iPhone app is entirely for show. I wanted to use an NSArray, but I think loading the data from a file will be much easier than that, since the tickets are going to be scanned, so I will already have all the numbers in a .txt file. How can I load 500 numbers from a txt file, with each of the 500 numbers on a line, totaling 500 lines? Is there some way to do something like:
Code:
NSArray *tickets = [NSArray arrayWithObjects:[pathToResource:"tickets" of type:"txt"]];
If that worked, it would be perfect
 

Nobita

macrumors 6502
Oct 5, 2008
425
2
La la land
You can't just do that. Google around. You basically have to do this in a kind of three steps:

1. Locate the file, get the path
2. Load the file
3. Convert them to NSArray.

BTW out of curiosity how did you format the file? Just numbers separated by line breaks? If it was more structured like XML or something like that it might be easier. Maybe.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.