[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: isKindOf: - GSObjCIsKindOf
From: |
Nicola Pero |
Subject: |
Re: isKindOf: - GSObjCIsKindOf |
Date: |
Tue, 28 Aug 2001 13:07:30 +0100 (BST) |
> Hello,
>
> Is there a way, knowing the name of two classes, test for
> the isKindOf relation without istantiating the receiver object:
>
> I have noticed that those methods in NSObject are defined so:
>
>
> - (BOOL) isKindOf: (Class)aClassObject
> {
> return [self isKindOfClass: aClassObject];
> }
>
> + (BOOL) isKindOfClass: (Class)aClass
> {
> if (aClass == [NSObject class])
> return YES;
> return NO;
> }
>
> - (BOOL) isKindOfClass: (Class)aClass
> {
> Class class = GSObjCClass(self);
>
> return GSObjCIsKindOf(class, aClass);
> }
>
>
> Is there a way other than using GSObjCIsKindOf
> directly to look if one class inherits from the other one ?
What about something like
#include <Foundation/Foundation.h>
@interface NSObject (ClassInheritance)
+ (BOOL) isSubclassOfClass: (Class)aPotentialSuperClass;
@end
@implementation NSObject (ClassInheritance)
+ (BOOL) isSubclassOfClass: (Class)aPotentialSuperClass
{
if (self == aPotentialSuperClass)
{
return YES;
}
else
{
Class c = self;
while (c != Nil)
{
c = [c superclass];
if (c == aPotentialSuperClass)
{
return YES;
}
}
return NO;
}
}
@end
and then of course in your code, you can test using
[NSString isSubclassOfClass: [NSObject class]]; // YES
[NSObject isSubclassOfClass: [NSString class]]; // NO
if you have the class name as a string you can always use
NSClassFromString () to get the Class pointer from the class name.
- Re: isKindOf: - GSObjCIsKindOf, (continued)
- Re: isKindOf: - GSObjCIsKindOf, Pascal Bourguignon, 2001/08/24
- Re: isKindOf: - GSObjCIsKindOf, Marko Mikulicic, 2001/08/25
- Re: isKindOf: - GSObjCIsKindOf, Nicola Pero, 2001/08/28
- Re: isKindOf: - GSObjCIsKindOf, Marko Mikulicic, 2001/08/29
- Re: isKindOf: - GSObjCIsKindOf, Stefan Böhringer, 2001/08/30
- Re: isKindOf: - GSObjCIsKindOf, Marko Mikulicic, 2001/08/30
- Message not available
- Re: isKindOf: - GSObjCIsKindOf, Stefan Böhringer, 2001/08/31
- Re: isKindOf: - GSObjCIsKindOf, Nicola Pero, 2001/08/30
Re: isKindOf: - GSObjCIsKindOf,
Nicola Pero <=