I've found a few similar questions to this but not relating to XCode.
I am creating an app where clicking a button generates a randomised quote and displays it in a label.
What I'd like to do is have a text file with all of the quotes, then have my app randomly select a quote from that file.
The problem is that my code at present reads the entire contents of the file.
textHIYP = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
textHIYP.editable = NO;
[self.view addSubview:textHIYP];
textHIYP.text = [NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Quotes" ofType:@"txt"] encoding:NSUTF8StringEncoding error:nil];
The only other way I can think of doing it is to have an arc4random() code that randomises which file it locates, with each file containing a single quote...but as I want to have over a hundred quotes, this seems less than ideal.
Any suggestions as to how to read a particular line of a text file?
Thanks heaps in advance!
See Question&Answers more detail:os