简体   繁体   中英

NSMutableArray insertObject atIndex

I have NSMutableArray *myArray = nil; . If I will use [myArray insertObject:@"Hello" atIndex:0] method to this array, will it be allocated automatically?

No. It will just send the message to nil.

It would be equivalent to;

[nil insertObject:@"Hello" atIndex:0];

NSMutableArray *nil = [NSMutableArray alloc]init];

[nil insertObject:@"How" atIndex:0];

Nope. Objective-C lets you message nil, so [myArray insertObject:@"Hello" atIndex:0] becomes [nil insertObject:@"Hello" atIndex:0] and will take the fast path in the runtime to doing nothing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM