Unknown Type Name NSTextField


#1

Hi,

I just purchased your ‘Cocoa Programming for Mac OS X 4th Edition’ and am having trouble getting started with your code example. I continue to receive an error stating: unknown type name ‘NSTextField’ in the Chapter 2 Let’s Get Started Random Number generator example. I am running xCode 6.0.x and OS X 10.9.5. Any help in resolving this would be very much appreciated. Thanks in advance for your help.

this is the code I have in the RandomController.h file:

#import <Foundation/Foundation.h>

@interface RandomController : NSObject {
IBOutlet NSTextField *textField;
}
-(IBAction)seed:(id)sender;
-(IBAction)generate:(id)sender;
@end


#2

That’s pretty strange!

I don’t have the latest and greatest version of Xcode, and the book was written for an older version.

However, first make sure that you have created a Cocoa Application, not an iOS one.

If you did create a Cocoa Application, then this may have something to do with the fact that you are using Xcode 6.0.x. Check to make sure that the Foundation framework (or its equivalent in Xcode 6.0.x) is added to your project.


#3

Dear,

I have solve this problem creating the RandomController Class, deactivating the “Target Membership” flag.
You can find this flag while you are creating the class, just when you must select the folder .

Also you can find this flag, when you select the RandomController.h file. Check the inspector area looking for “Target Membership” section and deactivate the flag.

I hope help you.

Please tell me if your code runs. my code Build OK, but do nothing!!!

BR,
Amable


#4

The only resolution I was able to come up with was adding: Cocoa.Framework and Foundation.Framework manually to the project. Also, when I downloaded the code for the book from the big nerd ranch site, the frameworks were already added to the project. It was not clear to me why it was necessary to do manually link the framework binaries (Cocoa and Foundation) to the project and import Cocoa.h in the RandomController header given that I selected Cocoa Application creation when creating the project and given the default import of foundation. Perhaps this was a change due to xCode 6.0.1.

It would be great if some of the Big Nerd’s could reply or identify a location where errata listing xCode changes can be found. Being new to OSX development and my understanding of the project code downloaded from BNR, it is not clear whether this stuff was auto added in the past or whether it is always necessary to manually add. Thanks


#5

I have got the same problem. The solution: only add the following line at beginning of the RandomController.f file

#import <AppKit/AppKit.h>

BR


#6

Sorry, I wanted to say: RandomController.h file


#7

You can also replace the line… [size=85]#import <Foundation/Foundation.h>[/size] with… [size=85]#import <Cocoa/Cocoa.h>[/size] as Xcode itself does in AppDelegate.h (that’s where I got the idea anyway). If you Cmd-Click the Cocoa.h import statement once you add it, and go to the definition file, Apple states that using Cocoa.h is preferable…