I have the following code:
id anArray = [NSArray arrayWithObjects:@1, @2, nil];
NSLog(@"anArrayClass - %@", [anArray class]);
NSLog(@"NSArrayClass - %@", [NSArray class]);
And I expect both output are NSArray
, however the output turns out to be:
2016-08-18 21:08:53.628 TestUse[9279:939745] anArrayClass - __NSArrayI
2016-08-18 21:08:53.629 TestUse[9279:939745] NSArrayClass - NSArray
Then I create a test class called CAJTestClass
and create an instance of that class:
id testInstance = [CAJTestClass new];
NSLog(@"testInstanceClass - %@", [testInstance class]);
NSLog(@"cajTestClass - %@", [CAJTestClass class]);
This time the output becomes:
2016-08-18 21:08:53.629 TestUse[9279:939745] testInstanceClass - CAJTestClass
2016-08-18 21:08:53.629 TestUse[9279:939745] cajTestClass - CAJTestClass
This time the result is what I expected. But why would [anArray class]
to be a __NSArrayI
?
An explanation from "Effective Objective-C" is that NSArray
is a part of a "class cluster"(which I think is a series of classes that have inheriting relationships). But CAJTestClass
is also a subclass of NSObject
. Am I wrong?
EDIT: Thanks for all your answers. But my question is exactly why I get different result in this two cases if it should contribute to the affairs of "class cluster"?