Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Gabberke

macrumors newbie
Original poster
Jun 19, 2013
4
0
Baal - Belgium
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
 
Last edited by a moderator:
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:
https://forums.macrumors.com/threads/747660/
 
Last edited:
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.
 
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

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.
 
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.

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.
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.