[英]NSMutableArray insertObject atIndex
I have NSMutableArray *myArray = nil;
我有
NSMutableArray *myArray = nil;
. 。 If I will use
[myArray insertObject:@"Hello" atIndex:0]
method to this array, will it be allocated automatically? 如果我将
[myArray insertObject:@"Hello" atIndex:0]
方法用于此数组,它将自动分配吗?
No. It will just send the message to nil. 不会。它只会将消息发送到nil。
It would be equivalent to; 等同于;
[nil insertObject:@"Hello" atIndex:0];
NSMutableArray *nil = [NSMutableArray alloc]init]; NSMutableArray * nil = [NSMutableArray alloc] init];
[nil insertObject:@"How" atIndex:0]; [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. Objective-C允许您发送nil消息,因此
[myArray insertObject:@"Hello" atIndex:0]
变为[nil insertObject:@"Hello" atIndex:0]
,它将在运行时采用快速路径进行任何操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.