Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Missing sentinel in function call?

Not sure why I get "Missing sentinel in function call?"

NSMutableArray *kkk = [NSMutableArray arrayWithObjects: @"a", @"b", @"cat", @"dog", nil];
ppp = [NSMutableArray arrayWithCapacity:3];
[ppp addObject:[[NSMutableArray alloc] initWithObjects: kkk]]; // <<--- Missing sentinel in function call
[ppp addObject:[[NSMutableArray alloc] initWithObjects: kkk, nil]]; //<<--- change, but it falls out

NSLog(@"Working: %@   %@", [[ppp objectAtIndex:0] objectAtIndex:3], [[ppp objectAtIndex:0] objectAtIndex:2] );
like image 466
Kristen Martinson Avatar asked May 22 '26 14:05

Kristen Martinson


1 Answers

initWithObjects: must be terminated with a trailing nil. Since it is a single object, you should be a able to use initWithObject:. That said, you will be leaking the array like this. Do

[ppp addObject:[NSMutableArray arrayWithObject:kkk]];

There is one more problem with the piece of code here,

NSMutableArray *kkk = [NSMutableArray arrayWithObjects: @"a", @"b", @"cat", @"dog", nil];
ppp = [NSMutableArray arrayWithCapacity:3];
[ppp addObject:[[NSMutableArray alloc] initWithObjects: kkk, nil]];

You are creating a three dimensional array. So

NSLog(@"Working: %@   %@", [[ppp objectAtIndex:0] objectAtIndex:3], [[ppp objectAtIndex:0] objectAtIndex:2] ); 

is wrong.

NSLog(@"Working: %@   %@", [[[ppp objectAtIndex:0] objectAtIndex:0] objectAtIndex:3], [[[ppp objectAtIndex:0] objectAtIndex:0] objectAtIndex:2] );

should log proper values.

However if you need a two dimensional array based on your log statement, I would say you need to do this instead,

[ppp addObject:kkk];
like image 133
Deepak Danduprolu Avatar answered May 25 '26 04:05

Deepak Danduprolu



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!