[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: isKindOf: - GSObjCIsKindOf
From: |
Pascal Bourguignon |
Subject: |
Re: isKindOf: - GSObjCIsKindOf |
Date: |
Sat, 25 Aug 2001 05:15:20 +0200 (CEST) |
Marko Mikulicic <mikulici@die.supsi.ch> wrote:
> 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);
> }
>
As you can see, there is a class method named isKindOfClass:. You can
send this message to a class. On another hand, all classes are always
instanciated, you don't loose anything invoking them, meaning that if
for syntactic reason you need to write [MyClass class] instead of
MyClass, there's no downside (AFAIK).
[MyFirstClass isKindOfClass:MySecondClass]
> Is there a way other than using GSObjCIsKindOf
> directly to look if one class inherits from the other one ?
>
> (I have no instances, only classes converted from strings).
If you only have the class name at run time stored in a NSString, you
can use the function NSClassFromString (found in NSObjCRuntime.h) to
get the class with the given name.
Class Class1=NSClassFromString(@"MyFirstClass");
Class Class2=NSClassFromString(@"MySecondClass");
if((Class1!=nil)&&(Class2!=nil)){
return([Class1 isKindOfClass:Class2]);
}else{
return(NO);
}
> Thanks
You're welcome.
> Marko
__Pascal__
--
__Pascal_Bourguignon__ (o_ Software patents are endangering
() ASCII ribbon against html email //\ the computer industry all around
/\ and Microsoft attachments. V_/ the world http://lpf.ai.mit.edu/
1962:DO20I=1.100 2001:my($f)=`fortune`; http://petition.eurolinux.org/
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCS/IT d? s++:++(+++)>++ a C+++ UB+++L++++$S+X++++>$ P- L+++ E++ W++
N++ o-- K- w------ O- M++$ V PS+E++ Y++ PGP++ t+ 5? X+ R !tv b++(+)
DI+++ D++ G++ e+++ h+(++) r? y---? UF++++
------END GEEK CODE BLOCK------
- isKindOf: - GSObjCIsKindOf, Marko Mikulicic, 2001/08/24
- Re: isKindOf: - GSObjCIsKindOf,
Pascal Bourguignon <=
- 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, 2001/08/28