Issues with Interactive User Interface example

Discussion in 'Mac Programming' started by Gabberke, Oct 28, 2013.

  1. Gabberke, Oct 28, 2013
    Last edited by a moderator: Oct 28, 2013

    Gabberke macrumors newbie

    Joined:
    Jun 19, 2013
    Location:
    Baal - Belgium
    #1
    Hello,

    I recently bought the book MAC Programming for absolute beginners.
    I've tried one of the example described in the book to connect some code to the User Interface, but the example doesn't work and I don't know what I am doing wrong. I have followed the instructions of the book. Can somebody help me?

    ".h file"
    Code:
    #import <Cocoa/Cocoa.h>
    
    @interface AppDelegate : NSObject <NSApplicationDelegate>
    {
        NSWindow *window;
        NSTextField *message;
    }
    
    @property (assign) IBOutlet NSWindow *window;
    @property (assign) IBOutlet NSTextField *message;
    
    -(IBAction)goodBye:(id)sender;
    
    @end
    ".m file"
    Code:
    #import "AppDelegate.h"
    
    @implementation AppDelegate
    [B]@synthesize window;
    @synthesize message;[/B]
    
    - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
    {
        NSLog (@"Hello World!");// Insert code here to initialize your application
    }
    
    -(IBAction)goodBye:(id)sender
    {
        message.stringValue = @"Good-bye";
    }
    
    @end
    The compiler always gives a "BUILD FAILED" for the 2 lines in BOLD
     
  2. chown33, Oct 28, 2013
    Last edited: Oct 29, 2013

    chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #2
    What is your OS X version?

    What is your Xcode version?

    Which edition of the book? Author's name?

    What page is the posted example on (so someone can look it up)?


    Referring to this:
    Encapsulating Data
    Most Properties Are Backed by Instance Variables
    ...
    Unless you specify otherwise, the synthesized instance variable has the same name as the property, but with an underscore prefix. For a property called firstName, for example, the synthesized instance variable will be called _firstName.
    See the rest of that reference doc for how you'd synthesize a property and bind it to a differently-named instance variable.


    Without knowing anything else, my guess is that the book is using an older Xcode version and an older compiler version, which are using a different rule for correlating an instance-variable's name to a property name.


    Finally, please read and follow this:
    http://forums.macrumors.com/showthread.php?t=747660
     
  3. Gabberke thread starter macrumors newbie

    Joined:
    Jun 19, 2013
    Location:
    Baal - Belgium
    #3
    I am using:

    OS X 10.8.5
    Xcode version 4.6.3
    Book: Mac Programming for Absolute beginners (Wallace Wang)
    Example is is on page: 33 - 42

    Thanks for your support.

    I think that it has something to do with the setting of Xcode because in the book they are using an older version of Xcode. But I don't have any clue.

    P.
     
  4. devilofspades macrumors member

    Joined:
    Jul 20, 2011
    #4
    first off take this portion out of your .h file.
    Code:
    {
        NSWindow *window;
        NSTextField *message;
    }
    
    if that doesn't resolve it, can you post the actual error message the compiler is giving you? did you cut and paste that code from xcode in your post? my guess is you have a typo somewhere, the code as you have it posted is perfectly valid and should compile just fine.
     
  5. chown33, Oct 29, 2013
    Last edited: Oct 29, 2013

    chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #5
    First, the book should tell you which version of Xcode it's written for. Look in the Introduction, or maybe the first chapter. Post what that version is.

    Second, almost ever programming book written for the last decade or so has a website that supports the book. Find what that website is, and visit it to see if there are changes for the book. It's usually listed in the Introduction of the book, or sometimes on the back cover. Here's the publisher's page for the book, which lists errata, among other things:
    http://www.apress.com/9781430233367

    Third, the "Encapsulating Data" link I posted earlier explains properties and instance-variables, and the naming relationship between them. Read the entire web-page, so you understand everything it tells you. I've already quoted the specific rule for correlating properties to instance-variable names, but you should read the entire thing so you get the whole picture. If you understand what it tells you, you should be able to change the code from the book so it compiles. You will have to learn a principle and apply it, instead of simply going through a worked-out example.
     

Share This Page