开发者

Confusion around NSMutableArray and NSArray

开发者 https://www.devze.com 2022-12-24 14:46 出处:网络
I have the following code: NSLog(@\"items: %d\", [items count]); NSLog(@\"allObjects: %d\", [self.allObjects count]);

I have the following code:

NSLog(@"items: %d", [items count]);
NSLog(@"allObjects: %d", [self.allObjects count]);

[self.allObjects addObjectsFromArray:items];

NSLog(@"allObjects: %d", [self.allObjects count]);

Wh开发者_如何学编程ich produces the following output:

items: 7
allObjects: 0
allObjects: 0

items is a NSArray

allObjects is a NSMutableArray.

I'm confused as to why the objects in items are not being added to allObjects. I expect it's something simple, but there is a hole in my understanding here.


Let me guess. self.allObjects is nil. Sending messages to nil is a no-op.

0

精彩评论

暂无评论...
验证码 换一张
取 消