addObjectsToArray: behaving badly - why?
addObjectsToArray: behaving badly - why?
- Subject: addObjectsToArray: behaving badly - why?
- From: "K. Darcy Otto" <email@hidden>
- Date: Sat, 12 Apr 2008 19:42:59 -0700
My code used to look like this:
NSMutableArray *newDependencies = [self.dependencies mutableCopy];
[newDependencies addObjectsFromArray:[aDependency dependencies]];
Now self.dependencies and [aDependency dependencies] both return
NSArrays. The code works very well provided that the array returned
by self.dependencies does not have 0 objects in it. But if the array
returned by self.dependencies does have 0 objects in it, then
newDependencies still has 0 objects in it after addObjectsFromArray is
executed. I was able to correct this behaviour with the following code:
NSMutableArray *newDependencies = [[NSMutableArray alloc] init];
[newDependencies addObjectsFromArray:self.dependencies];
[newDependencies addObjectsFromArray:[aDependency dependencies]];
This works fine even when the array returned by self.dependencies has
0 objects. But I'm puzzled as to why it functions differently than
the first version. Any ideas?
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden