how can I load the content of a txt file divided by lines in a NSArray? Basically, I have a file "count.txt" where I write the number of elements (and it works), "1t.txt" which represents the title of the first line and "1.txt" which represents the content. I mean just the adding of values value by value. Then when a user hits the title of the Table View I want he reads the content of "*.txt" (obviously easy if I have the index of array file)
For now I use this code:
- (void) loadMainArray
{
for (int i = 1; i <= max; i++)
{
NSString *currentNumber;
currentNumber = [NSString stringWithFormat:@"%it", i];
NSLog(@"%i° file read", i);
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *dataFilePath = [[NSBundle mainBundle] pathForResource:currentNumber ofType:@"txt"];
if ([fileManager fileExistsAtPath:dataFilePath])
{
NSString *content = [NSString stringWithContentsOfFile:dataFilePath encoding:NSUTF8StringEncoding error:nil];
NSArray *parsed = [content componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];
mainArray = (__bridge NSMutableArray*)CFPropertyListCreateDeepCopy(kCFAllocatorDefault, (CFPropertyListRef)parsed, kCFPropertyListMutableContainers);
NSLog(@"%@", parsed);
}
else{
}
}
}
(sorry if the code is not aligned as well but I'm not able so much in stackoverflow) Anyway, after calling this method in the ViewLoad I get Signal SIGABRT, where I'm wrong?
N.B: max is set as well, I checked in NSLog. mainArray is an NSMutableArray.