• 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: Accessor works intermittently
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Accessor works intermittently


  • Subject: Re: Accessor works intermittently
  • From: Greg Parker <email@hidden>
  • Date: Thu, 1 Oct 2009 11:44:22 -0700

On Sep 30, 2009, at 7:56 PM, Stephen J. Butler wrote:
On Wed, Sep 30, 2009 at 6:41 PM, David Hirsch <email@hidden> wrote:
I cannot figure out why this does not work:

               Phase *thisPhase = [phases objectAtIndex:i];
               float testmode = [thisPhase mode];
               float testmode2 = [[phases objectAtIndex:i] mode];

Following along with the code execution in the debugger, testmode gets the
correct value, but testmode2 gets an erroneous value. Note that phases is
an NSMutableArray of Phase* and mode is a trivial accessor for a float
stored inside Phase:


- (float) mode {return mode;}

Something else, probably in Cocoa, is defining a "mode" selector before you do with a different return type. When ObjC can't determine the exact signature of a selector (for example, because the instance type is "id") it uses the first one it finds. Searching through the header files, I see at least two candidates it's probably choosing:

./AppKit.framework/Versions/C/Headers/NSColorPanel.h:- (NSColorPanelMode)mode;
./AppKit.framework/Versions/C/Headers/NSMatrix.h:- (NSMatrixMode)mode;

Recent versions of Xcode warn about this problem:
test.m: In function ‘main’:
test.m:15: warning: multiple methods named ‘-mode’ found
/System/Library/Frameworks/AppKit.framework/Headers/NSMatrix.h: 123: warning: using ‘-(NSMatrixMode)mode’
test.m:6: warning: also found ‘-(float)mode’
/System/Library/Frameworks/AppKit.framework/Headers/ NSColorPanel.h:97: warning: also found ‘-(NSColorPanelMode)mode’



You can make it work with:

float testmode2 = [(Phase*)[phases objectAtIndex:i] mode];

Another option is to rename your -mode method.


-- Greg Parker email@hidden Runtime Wrangler


_______________________________________________

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


  • Prev by Date: Re: Why is scrollbar enabled? - SOLVED
  • Next by Date: Re: [iPhone] Application running for the very first time...
  • Previous by thread: Re: Accessor works intermittently
  • Next by thread: Re: NSDocumentController didCloseAllSelector
  • Index(es):
    • Date
    • Thread