Reputation: 1480
I have a .txt
file in which some data is present, when I stored it in an array I got 50000 words. I want to search the data from text file according to user input and show it on UITableview
cell, how is it possible ?
Can any body help me?
Here is my code to read data from .txt
file in viewDidLoad
:
NSString *filepath = [[NSBundle mainBundle] pathForResource:@"myList" ofType:@"txt"];
NSError *error;
NSString *fileContents = [NSString stringWithContentsOfFile:filepath encoding:NSUTF8StringEncoding error:&error];
if (error)
NSLog(@"Error reading file: %@", error.localizedDescription);
// maybe for debugging...
NSLog(@"contents: %@", fileContents);
NSArray *listArray = [fileContents componentsSeparatedByString:@"\n"];
NSLog(@"items = %d", [listArray count]);
Upvotes: 0
Views: 76
Reputation: 2360
You should use fast enumeration using block. Those are fastest of all for loop iteration. But changing the value in that array at time of enumeration could cause a crash.
Here is a link of how to use block enumeration
Here is a link of how it performance wise.
Hope this helps you!!
Upvotes: 1