Re: Class method not working. Why?
Re: Class method not working. Why?
- Subject: Re: Class method not working. Why?
- From: Phillip Morelock <email@hidden>
- Date: Sat, 22 Jun 2002 12:01:13 -0700
>
"warning: Foo does not respond to rootObject"
>
>
... in these lines of code
>
>
[newWidget setParent:[self rootObject]];
>
>
[[[self rootObject] childList] addObject: newWidget];
>
>
NSEnumerator *widgetEnumerator = [[[self rootObject] childList]
>
objectEnumerator];
That's because you're probably in an instance context when you call [self
rootObject]; That means you're inside of a minus - method instead of a
plus + method.
So self is the instance of this object, rather than "self" in your + method,
where "self" is the **class**.
does this make sense? Basically, unless you're in another + method in the
same class, you generally need to address to class by name [Foo rootObject];
Or if you're in the same class file you might use [self->isa rootObject] but
that's a little more hacktastic.
cheers
fillup
On 6/22/02 11:37 AM, "Ken Tozier" <email@hidden> wrote:
>
I wrote a class method to cash the root object for my outline view and
>
keep getting warnings when I go to run the project. Anyone out there
>
point out what I'm doing wrong?
>
>
Defined in "Foo.h"
>
+(id) rootObject;
>
>
>
Defined in "Foo.m"
>
+ (id) rootObject
>
{
>
static Foo *rootObject = nil;
>
>
if (rootObject == nil)
>
{
>
rootObject = [[self alloc] init];
>
}
>
>
return rootObject;
>
}
>
>
>
And I get the following warning when I go to run it ...
>
>
"warning: Foo does not respond to rootObject"
>
>
... in these lines of code
>
>
[newWidget setParent:[self rootObject]];
>
>
[[[self rootObject] childList] addObject: newWidget];
>
>
NSEnumerator *widgetEnumerator = [[[self rootObject] childList]
>
objectEnumerator];
>
>
>
Thanks for any help
>
>
Ken Tozier
>
_______________________________________________
>
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.
_______________________________________________
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.