• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Class method not working. Why?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

References: 
 >Class method not working. Why? (From: Ken Tozier <email@hidden>)

  • Prev by Date: Class method not working. Why?
  • Next by Date: [Solved] Class method not working. Why? - Thanks
  • Previous by thread: Class method not working. Why?
  • Next by thread: [Solved] Class method not working. Why? - Thanks
  • Index(es):
    • Date
    • Thread