Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getting NSArray length/count - Objective C

Well I've looked at similar problems over the site but haven't reached a solution thus far so I must be doing something wrong.

Essentially, I am importing a text file, then splitting each line into an element of an array. Since the text file will be updated etc.. I won't every know the exact amount of lines in the file and therefore how many elements in the array. I know in Java you can do .length() etc.. and supposedly in Objective C you can use 'count' but i'm having no luck returning the length of my array... suggestions?

 NSString *filePath = [[NSBundle mainBundle] pathForResource:@"allshows" 
                                                     ofType:@"txt"];
 NSString *fileString = [NSString stringWithContentsOfFile:filePath];

NSArray *lines = [fileString componentsSeparatedByString:@"\n"];  

NSUInteger *elements = [lines count];
NSLog(@"Number of Shows : ", elements);

and what is being output is NOTHING. as in "Number of Shows : " - blank, like it didn't even count at all.

Thank you for any help!

like image 236
Didier Avatar asked Oct 20 '11 16:10

Didier


1 Answers

You're missing the format string placeholder. It should be:

NSLog(@"Number of shows: %lu", elements);
like image 70
omz Avatar answered Oct 26 '22 17:10

omz