Reputation: 327
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!
Upvotes: 16
Views: 53552
Reputation: 21019
Looking at your other post, it seems like you are a Java developer. In Java's System.out, you just append the variables. In Objective-C, I suggest you look at "print format specifiers". Objective-C uses the same format.
Upvotes: 0
Reputation: 53551
You're missing the format string placeholder. It should be:
NSLog(@"Number of shows: %lu", elements);
Upvotes: 17
Reputation: 19251
You need to use a format specifier to print an integer (%d
):
NSLog(@"Number of Shows : %d", elements);
Upvotes: 6