One thing I’m a bit unclear on is the difference between these NSMutableArray Methods:
// Class Method Style
NSMutableData *myMutableDataInstance = [NSMutableData dataWithLength:WholeLottaData];
and
// Instance Method Style
NSMutableData *myMutableDataInstance = nil;
myMutableDataInstance = [[[NSMutableData alloc] initWithLength:WholeLottaData]] autorelease];
Under the hood, what eactly is the class method doing here? How does it differ from the instance method?
Cheers,
Doug
The class method creates and autoreleases an NSMutableArray object.
The instance method initialzes an object that you have to allocate yourself. The code you’ve written won’t actually do anything, because
myMutableArrayInstanceisnil. The class method is roughly equivalent to this:And as Peter Hosey notes in comments, it really means this:
which will have different results from the above if the
initWithCapacity:method returns a different object.