NSArray cluster class membership
NSArray cluster class membership
- Subject: NSArray cluster class membership
- From: Marco Scheurer <email@hidden>
- Date: Tue, 2 Mar 2004 22:51:41 +0100
Hello list,
I was browsing the "Porting OGo to MacOSX" page at
http://www.opengroupware.org/en/projects/macosx/ where I found:
"on Cocoa we cannot find out whether an array is mutable - affects
NGObjWeb and is hacked around using NS_DURING".
I was sure that this had been corrected in a recent release of Mac OS
X, but apparently not. I typed the unit tests below and sure enough,
some tests fail:
Lab/Test.m:17: -[Test testClassMembership] : [[NSArray array]
isMemberOfClass:[NSArray class]] should be true
Lab/Test.m:18: -[Test testClassMembership] : [[NSArray array]
isKindOfClass:[NSMutableArray class]] should be false
Lab/Test.m:22: -[Test testClassMembership] : [[NSMutableArray array]
isMemberOfClass:[NSMutableArray class]] should be true
Lab/Test.m:26: -[Test testClassMembership] : [[NSArray array]
respondsToSelector:@selector(addObject:)] should be false
The errors with isMemberOfClass: can be explained because the cluster
actually returns an instance of a subclass of NSArray for [NSArray
array]. It's still shocking from a semantic point of view, and I'm not
sure what would be lost if [[NSArray array] isMemberOfClass:[NSArray
class]] returned YES, but OK, maybe it's a price to pay for clusters.
It's even worse for the 2 others, but as I said, I was pretty sure
these had been fixed (ie, isKindOfClass: and respondsToSelector: had
been tweaked to return the correct result). Was it a dream?
Marco Scheurer
Sen:te, Lausanne, Switzerland
http://www.sente.ch
------------------
@implementation Test
- (void) testClassMembership
{
should ([[NSArray array] isKindOfClass:[NSArray class]]);
should ([[NSArray array] isMemberOfClass:[NSArray class]]);
shouldnt ([[NSArray array] isKindOfClass:[NSMutableArray class]]);
shouldnt ([[NSArray array] isMemberOfClass:[NSMutableArray class]]);
should ([[NSMutableArray array] isKindOfClass:[NSMutableArray class]]);
should ([[NSMutableArray array] isMemberOfClass:[NSMutableArray
class]]);
should ([[NSMutableArray array] isKindOfClass:[NSArray class]]);
shouldnt ([[NSMutableArray array] isMemberOfClass:[NSArray class]]);
shouldnt ([[NSArray array] respondsToSelector:@selector(addObject:)]);
}
@end
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.