Weird problem with NSString initWithContentsOfFile
I have a .csv file in my bundle which I need to parse into an NSArray. The problem is when I init an NSString with contents of file (the file is located in my bundle), it returns nil. However, if I change the contents of the file, to anything else (random), it works. Is it possible there's some sort of string/character in the file that might be messing with the initialization?
It's just a simple csv file with 2 columns, a number, a comma, some text and "\n".
CSV => NSArray?
*disclaimer: I wrote it.
Works for me:
NSStringEncoding usedEncoding = 0; NSError *csvError = nil; NSString *raw = [NSString stringWithContentsOfURL:[NSURL URLWithString:@"http://pastebin.com/raw.php?i=RXPPwpvy"] usedEncoding:&usedEncoding error:&csvError]; NSLog(@"raw: %@", raw); NSLog(@"%@", [NSArray arrayWithContentsOfCSVString:raw encoding:usedEncoding error:&csvError]);