开发者

Is Cocoa Programming for Mac OS X (3rd edition) outdated? [closed]

开发者 https://www.devze.com 2023-01-22 10:32 出处:网络
Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this
Closed. This question needs to be more focused. It is not currently accepting answers.

Want to improve this question? Update the question so it focuses on one problem only by editing this post.

Closed 8 years ago.

Improve this question

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:

Is Cocoa Programming for Mac OS X (3rd edition) outdated? [closed]

Is Cocoa Programming for Mac OS X (3rd edition) outdated? [closed]

Is Cocoa Programming for Mac OS X (3rd edition) outdated? [closed]

Is Cocoa Programming for Mac OS X (3rd edition) outdated? [closed]

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.


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". ;-)


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

Is Cocoa Programming for Mac OS X (3rd edition) outdated? [closed]

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

Is Cocoa Programming for Mac OS X (3rd edition) outdated? [closed]

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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消