I am trying to get to know the C lens, and my current goal is to read the list of elements in a text file and save them in an NSString array.
This is currently what I have:
NSString *filepath = [[NSBundle mainBundle] pathForResource:@"myList" ofType:@"txt"];
NSData* data = [NSData dataWithContentsOfFile:filepath];
NSString* string = [[NSString alloc] initWithBytes:[data bytes]
length:[data length]
encoding:NSUTF8StringEncoding];
NSString* delimiter = @"\n";
listArray = [string componentsSeparatedByString:delimiter];
I am not sure if this is important, but myList.txtis in my supporting files.
At the moment, I have only one item in my list. However, I cannot save even this 1 element to my own listArray.
I'm sure this is something stupid that I am missing, I'm just new to Objective C.
EDIT:
I apologize for not mentioning this before. I do NOT accept any mistake. My array is null.
source
share