• 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: Clueless about this warning
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Clueless about this warning


  • Subject: Re: Clueless about this warning
  • From: "Jonathan del Strother" <email@hidden>
  • Date: Sat, 4 Oct 2008 15:49:50 +0100

On Sat, Oct 4, 2008 at 3:43 PM, Andre Masse <email@hidden> wrote:
> Hi,
>
> Can someone explain to me why I get this compiler warning (BigLetterView is
> a subclass of NSView):
>
> 'BigLetterView' may not respond to '-prepareAttributes'
>
>
>
> - (id)initWithFrame:(NSRect)rect {
>
>        if(![super initWithFrame:rect]) {
>                return nil;
>        }
>        NSLog(@"intializing view");
>        [self prepareAttributes]; // <------------ warning on this line
>        bgColor = [[NSColor yellowColor] retain];
>        string = @" ";
>
>    return self;
> }
>
> while later in the same source file, the following method is defined:
>
> - (void)prepareAttributes
> {
>        NSLog(@"prepareAttributes called");
>        attributes = [[NSMutableDictionary alloc] init];
>        [attributes setObject:[NSFont fontWithName:@"Helvetica" size:75]
> forKey:NSFontAttributeName];
>        [attributes setObject:[NSColor redColor]
> forKey:NSForegroundColorAttributeName];
> }
>
> I know I can fix this easily by declaring prepareAttributes in the header
> file or in an @interface block in the '.m' file, but I'm curious why I get
> this warning if an only if I make the call in the initWithFrame method.
> Calling [self prepareAttributes] in any other method doesn't generate any
> warning.
>
> Does calling an instance method in the initialization phase require
> something special?
>


I'm guessing that the times where it doesn't warn occur after "-
(void)prepareAttributes" ?
To avoid those warnings, the method declaration or definition needs to
appear before it's used.  I usually add a private category at the top
of my .m files where you can declare private methods - something like
this :

@interface BigLetterView ()
- (void)prepareAttributes;
@end

@implementation BigLetterView
- (id)initWithFrame:(NSRect)rect {
...
}
-(void)prepareAttributes {
...
}
@end
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Class Extensions (Re: Clueless about this warning)
      • From: Bill Bumgarner <email@hidden>
    • Re: Clueless about this warning
      • From: Andre Masse <email@hidden>
References: 
 >Clueless about this warning (From: Andre Masse <email@hidden>)

  • Prev by Date: Clueless about this warning
  • Next by Date: Re: Clueless about this warning
  • Previous by thread: Clueless about this warning
  • Next by thread: Re: Clueless about this warning
  • Index(es):
    • Date
    • Thread