• 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
Interference of a variable name with Interface Builder
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Interference of a variable name with Interface Builder


  • Subject: Interference of a variable name with Interface Builder
  • From: Jochen Moeller <email@hidden>
  • Date: Sat, 12 Jun 2010 23:11:43 +0200

Hello List,

Normally variable names don't interfere with method names. So I can write:

  CGFloat alphaValue = [ myCustomView alphaValue ];

Now, in an app the -drawRect: method of my custom view was not called although it should. I found out that the culprit was an outlet named "alphaValue" which is also an NSView method. Here is the tracked down example.

Xcode 3.2.2, IB 3.2.2, GCC 4.2, Architecture: 10.6 | Debug | x86_64
A new Cocoa App with the following NSView subclass:

//  MyView.h
#import <Cocoa/Cocoa.h>
@interface MyView : NSView {
  IBOutlet NSTextField *alphaValue;
}
@end

//  MyView.m
#import "MyView.h"
@implementation MyView
- (id)initWithFrame:(NSRect)frame {
    NSLog(@"%@", NSStringFromSelector(_cmd));
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code here.
    }
    return self;
}

- (void)drawRect:(NSRect)rect {
    NSLog(@"%@", NSStringFromSelector(_cmd));
    [[ NSColor whiteColor ] set ];
    NSRectFill(rect);
}
@end

In IB drop a custom view and assign it to MyView.
Then drop a label into the window without connecting it.
In Xcode Build & Run -> -drawRect: method is called and a white rectangle is shown.

Now connect in IB the label with the outlet of MyView and Run again.
-> -drawRect: is not invoked, no rectangle is drawn, and no error or warning appeares.

Funny, or ?

I hope you can reproduce it.

I solved the problem by renaming the outlet to "alfaValue".

Is it in general better to avoid outlet names that are also method names?

Best
Jochen Moeller_______________________________________________

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:
    • Re: Interference of a variable name with Interface Builder
      • From: Kyle Sluder <email@hidden>
  • Prev by Date: Re: Type of NSData contents
  • Next by Date: Re: NSTrackingArea pending install - NSTrackingEnabledDuringMouseDrag not working
  • Previous by thread: Re: userDefaultsDidChange is causing a loop with dependent checkbox values
  • Next by thread: Re: Interference of a variable name with Interface Builder
  • Index(es):
    • Date
    • Thread