views:

92

answers:

3

Hi Stack Overflow,

got a quick question for you (pretty much the title): is the book Cocoa Programming for Mac OS X (3rd Edition) outdated?

It's just that I read a little in it, until page 36 (in a .PDF ebook version) where I came across a problem. The chapter introduces you to Objective-C and Cocoa, and you already have to write a program by yourself. Exciting. But when he makes a class called Foo.h and Foo.m, my Xcode doesn't follow the guide.

  1. His Interface Builder is different from my Interface Builder.
  2. When he is about to make outlets and actions, I can't do it. They just won't show up.

I am sure I entered the correct info in my Foo.h file:

#import <Cocoa/Cocoa.h>


@interface Foo : NSObject {
 IBOutlet NSTextField *textField;
}

-(IBAction)seed:(id)sender;
-(IBAction)generate:(id)sender;
@end

the Foo.m file:

#import "Foo.h"

@implementation Foo

@end

and I dragged them both to the "Class" folder, but it still won't show them in IB. Besides that, Xcode shows three warnings:

  • Incomplete implementation of class 'Foo'
  • Method definition for '-generate:' not found
  • Method definition for '-seed:' not found

This is why I think the book is outdated, but these are not errors, just warnings.

Here's some screenies:

How his looks vs. how mine look

How his looks vs. how mine look

This just made me think that the book might be outdated, and if I can use it all (if there are mistakes in every chapters). Is it me that made a stupid mistake, or is the book really outdated?

Please help me out on this one, as I really want to learn Objective-C and Cocoa :) Thank you.

+3  A: 

No it's not outdated, you should just keep on reading and a few pages later you will find the instructions to write the definition of the generate: and seed: methods. The lack of that definition is what the compiler is complaining about.

From the "How to read this book" section: "Usually the help you seek will be only a paragraph or two away". ;-)

Fernando
Thank you for this, I guess I just have to read the chapter to end, then skim the text again for things that didn't make sense in the first place, and see if they do now.
ninjaboi21
I have just read the whole chapter through, and I can say: the application does not work.I am not sure what the problem is, I wrote every line of code he did, in the correct file, in the correct folder, but it still doesn't work.The three warnings is gone, so I must be on the right track, but they just don't show up in the Interface Builder. Besides that, I noticed his file is called MainMenu.nib, where mine is called MainMenu.xib. Does that make a different?I'm just lost on this one, what the source of the problem is. Please help me on this one. Thank you very much.
ninjaboi21
A: 

Yeah, I haven't read that book but Fernando offers sound advice. Read on, you haven't implemented the methods. If you just want to make the compiler happy, you could change the code to:

#import "Foo.h" 

@implementation Foo 

-(IBAction)seed:(id)sender {

}

-(IBAction)generate:(id)sender {

}


@end 

But that doesn't do anything yet. :)

BobbyShaftoe
It made the compiler happy, but not my Interface Builder.Did wrote some more in the other answer, if you want to take a look.
ninjaboi21
+1  A: 

The book worked fine when I started building apps on Snow Leopard. A few things like "NIB" vs. "XIB" crop up, but the concepts are the same. Now on to your problem.

You won't see any connections in the Identity tab for your class when using a version of Interface Builder that is later than was used in the book. You want the connections tab for that.

Best I can tell from your screenshots, your class is in IB but the connections aren't listed. Are you actually referencing the correct class? Perhaps you have a few "foo.h" files floating around and grabbed the wrong one. Here's how to tell. Open the Library window in IB if it's not already open. In the search box at the bottom, type "foo". alt text

In the pulldown that says "Inheritance", change it to "Definitions". You'll see something similar to this: alt text

If it doesn't say "2 actions, and 1 outlet", you've got the wrong file (I know your file works because I pasted it in to write this up). Confirm the contents of the file that IB is using by clicking "foo.h". That will open the file in Xcode. Make sure it contains what you think it contains.

mikestew
I am not sure what I do wrong, because I still can't find it. I looked over at the library, found my Foo but there was no outlet or actions. Should I try to upload the Xcode Project for you to check it? Thank you again
ninjaboi21
Click on foo.h in the Library window (second image above), and it will open the foo.h it is using. Add your outlets and actions in that file, and your connections should then work.
mikestew
I am not sure what I did this time, but it finally showed up! I am positive that I made a mistake, because this time, Foo was listed under "Subclasses of NSObject" instead of "Other Classes". I did not modify anything in Xcode, and I do not think in IB either, but it works now. When I click on the buttons (in the App), it changes value :) Thank you for the help tho!
ninjaboi21