Re: [MyClass class] returning superclass's class
Re: [MyClass class] returning superclass's class
- Subject: Re: [MyClass class] returning superclass's class
- From: Ken Tozier <email@hidden>
- Date: Thu, 20 Nov 2008 07:52:26 -0500
On Nov 20, 2008, at 6:46 AM, Alexander Spohr wrote:
Ken,
Your Mails title says „[MyClass class] returning superclass's class“
which is not true and Andy just proved that.
I guess if you never instantiate any actual objects then Andy "proved"
it, but try to create an object using one of the superclass's methods
and I think I proved that it doesn't in fact return expected results.
As Jean-Daniel said, this is a class cluster and a "feature" of the
class cluster implementation, but it is highly counterintuitive.
[MyClass class] should return the class used to instantiate an object,
not some undocumented mystery class somewhere in a class cluster.
I got it working for my purposes by embedding an NSCharacerSet as a
property of MyClass, so all is good, but [MyClass class] returning an
undocumented class is wrong, in my opinion.
Thanks all for the tips
Ken
You are talking to a class-cluster. The whitespaceCharacterSet call
is answered by NSCharacterSet, not by your subclass. And
NSCharacterSet will return a subclass that NSCharacterSet thinks
will fit your requirements best.
Please read about class-clusters as Jean-Daniel already pointed out.
atze
Am 20.11.2008 um 11:37 schrieb Ken Tozier:
@interface KOptionString : NSCharacterSet
{
}
@end
KOptionString *whiteTest = [KOptionString whitespaceCharacterSet],
*hexTest = [KOptionString characterSetWithCharactersInString:
@"0123456789abcdefABCDEFxX"];
NSLog(@"whiteTest %@", [whiteTest class]);
NSLog(@"hexTest %@", [hexTest class]);
whiteTest result -> NSBuiltinCharacterSet
hexTest result -> NSCFCharacterSet
On Nov 19, 2008, at 8:48 AM, Andy Lee wrote:
Works for me:
@interface MyClass : NSCharacterSet
@end
@implementation MyClass
@end
...
NSLog(@"[MyClass class] returns [%@]", [MyClass class]);
2008-11-19 08:44:27.891 Scratch2[24671:10b] [MyClass class]
returns [MyClass]
Can you post some code?
--Andy
_______________________________________________
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