Re: isKindOfClass vs. loading bundles: nope?!?!?!?
Re: isKindOfClass vs. loading bundles: nope?!?!?!?
- Subject: Re: isKindOfClass vs. loading bundles: nope?!?!?!?
- From: Andy Lee <email@hidden>
- Date: Thu, 21 Mar 2002 11:11:07 -0500
At 4:07 PM +0100 3/21/02, Ondra Cada wrote:
On Thursday, March 21, 2002, at 10:52 , Andy Lee wrote:
No, the zero makes sense. Remember, "class" is a Class, not an instance.
If you wanted to see a 1 instead of the 0, you could change that
NSLog line to:
NSLog(@"got a class %@ (%d)",s,
[[[class alloc] init]
isKindOfClass:[MLLoadableObject class]]);
(i) it would seem kind of silly to make an instance just to check
class relationship, would it not?
Yes it would. The code I wrote would also obviously have a memory
leak, and shouldn't call -init, come to think of it. I was just
trying to illustrate the point by claiming the above code would spit
out a 1 instead of a 0 (which you could try for yourself if you
didn't believe it, and then ask yourself why, what's the difference).
(ii) all NSObject instance methods are by definition class methods too
Strictly speaking, no, instance methods are never class methods.
What is true is that variables of type Class respond to NSObject
instance methods by virtue of the fact that they are treated as
quasi-objects.
I could be wrong, but I suspect there is no built-in "+descendsFromClass:
" method that does the same as your +ocs_isKindOfClass:. If there
were, I'd expect it to have been declared in
/usr/include/objc/Object.h.
Nope, that's old compatibility API. Foundation.framework/Headers/NSObject.
h is the place.
I stand corrected. I was grepping through NSObject.h, objc.h, etc.
trying to find a "+descendsFromClass:" type of method, and stumbled
on Object.h.
You could add it in a category.
That I did, but am still kinda bewildered that such a very basic
thing like kindOfClass: does not work?!?
You have to understand the datatype of your "class" variable and what
-isKindOfClass: does. The doc for -isKindOfClass: says:
- (BOOL)isKindOfClass:(Class)aClass
Returns YES if the receiver is an instance of aClass or an instance
of any class that inherits from aClass, NO otherwise.
A variable of type Class (with a capital C) is not an instance of
*any* class, so -isKindOfClass: is giving you the right answer.
--Andy
_______________________________________________
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.