Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to limit NSArray output in NSLog

I'd like to limit the output of an NSArray.

If my NSArray has, say 5 NSStrings in it:

NSArray *alphaList = [NSArray arrayWithObjects:@"v", @"w", @"x", @"y", @"z", nil];

Obviously coding:

NSLog(@"%@", alphaList);

Will output all 5 NSString objects.

I'm wondering if there's a way to limit the output to "n" number of objects.

I was hoping there'd be a way to do this through adding a number to the format specifier but it doesn't look like that's possible.

Any suggestions?

like image 717
Orpheus Mercury Avatar asked Dec 06 '25 02:12

Orpheus Mercury


1 Answers

NSLog(@"%@", [alphaList subarrayWithRange:NSMakeRange(0, n)]);
like image 141
sch Avatar answered Dec 07 '25 19:12

sch



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!