Where is NSTextField? - objective-c

I'm brand new to Mac OS X development. Primarily a Java and C# developer.
I'm reading this book and trying a few examples from the book.
In my AppController class, I'm trying to add an IBOutlet as follows :
IBOutlet NSTextField *textField;
It gives me an error saying "Unknown type name 'NSTextField'.
I have imported Foundation/Foundation.h
Please help.

#import <Cocoa/Cocoa.h>
Import this in your AppController header file

Related

YTPlayerView not found issue

Currently i have kinda strange issue with YTPLayerView. I already have a project that contains both Objective-C and Swift codes. So, I need to use Youtube Player in Objective-c. The problem is that when i declare my Objective-c View Controller in Bridging-Header my Objective-C header file fives an error "'YTPlayerView.h' file not found", but this error do not occurs when my Bridging header is empty. Maybe i forgot something to include idk. Can someone help me?
This is my Bridging Header code:
#import "CameraViewController.h";
This is my CameraViewController.h file:
#import UIKit;
#import "YTPlayerView.h"
#interface CameraViewController : UIViewController<YTPlayerViewDelegate>
#property(nonatomic, strong) IBOutlet YTPlayerView *playerView;
#end
I have already installed the podfile for youtube player:
use_frameworks!
target 'MyApp' do
pod 'youtube-ios-player-helper', '~> 0.1.4'
end
Thank you in advance!
Try to do:
#import <youtube_ios_player_helper/YTPlayerView.h>

Cocoa ViewController.m vs. Cocoa Touch ViewController.m

Total newbie question follows...
I am learning Objective C based Cocoa (OS X) app development. Most of the books and videos I have are iOS based, so I'm seeing how the two platforms differ.
I have converted a simple iOS app to OS X. I got the converted OS X app to work fine, but I have a question: Why doesn't OS X ViewController.m file have an #interface section?
I created the iOS app using Interface Builder, dragging UI elements from Main.Storyboard to ViewController.m, in the assistant editor. I dragged a UILabel cell into the #interface section of ViewController.m, created an instance variable #property. In iOS, the ViewController.h public #interface section remains empty.
In the OS X app, I dragged an NSTextField cell to the #interface section of the ViewController.h file to create a similar instance variable.
Is the OS X ViewController.h #interface section the correct place for IBOutlets? Doesn't this expose these instance variables to other classes? In the iOS case, since the instance variables were NOT added to the ViewController.h file, I assume they are hidden, correct? Can I make the OS X instance variables private?
As I mentioned, the OS X code works, I'm just trying to understand the differences between the platforms, and make sure I am headed in the right direction.
Before I answered I wanted to check if the same happened to me-- but when I created a custom NSViewController in a new iOS OR OS X app, both would generate the #interface in the implementation file (.m file)
So I'm not sure why you are seeing that.
However, to answer your question, (as you said) properties declared in the #interface in your header file (.h) are public. While properties declared in the #interface in the implementation are private. This is because the #interface inside of your implementation is called an "Extension". Which is basically just an anonymous "Category".
Unless outside objects need a reference to your outlets, then I would continue placing them inside of your implementation file. If for whatever reason one isn't generated for you, there is nothing wrong with manually typing out your own class extension to declare the properties
Yes you are right instance variable should not added to ViewController.h file to make them private. Same like you can make instance variables as private variables in OS X . Like this`#interface MasterViewController ()
#property (nonatomic, weak) NSString* strTemp;
#end
#implementation MasterViewController
You can get difference between cocoa and cocoa touch by already posted question for this

Can't create outlets in xcode 6.0

I'm reading the book IOS Programming The Big Nerd Ranch Guide 4th Edition.
I have come to the section where I should make a outlet connection.
I have the following code:
#interface BNRQuizViewController ()
#property (nonatomic, weak) IBOutlet UILabel *questionLabel;
#property (nonatomic, weak) IBOutlet UILabel *answerLabel;
#end
#implementation BNRQuizViewController
#end
In the book it says:
I only get this in my xcode:
Anyone who can help me?
You probably didn't set the custom class on your xib, in the right sidebar:
However, you should refrain from creating the view controllers and xibs separately, I suggest you use storyboards, or create a xib along with your header and implementation files by selecting the proper checkmark to avoid having xibs with a different name and deattached from your view controller.

Cannot access UIImage class without importing UIKit.h in Xcode 6?

#import <Foundation/Foundation.h>
#interface FaceObject : NSObject
#property (strong, nonatomic) UIImage *image;
#end
Xcode gives an error saying "unknown type name 'UIImage' unless I import UIKit.h, but in Xcode 5 i would have not gotten this error and did not need to import UIKit -- is there any explanation for this? Am I doing something wrong? Thanks!
In 2015 -- still getting this error. I always forget to include
#import <UIKit/UIKit.h>
That should take care of it.
Xcode 6 no longer includes a .pch file by default. In previous versions, that file included the UIKit import (more info here - Why isn't ProjectName-Prefix.pch created automatically in Xcode 6?).

Objective-C: Expected identifier or '(' and 3 unknown errors during compilation

I face 3 unknown errors during compile suddenly in AppDelegate.h file of a project which was going alright for a month.
which are!
Parse Issue - Expected identifier or '('
Parse Issue - Expected ')'
Semantic Issue - Unknown type name 'ViewController'; did you mean 'UIViewController'?
I checked my code line by line there is no syntax error or Semantic issue (i have ViewController.h , ViewController.m and ViewController.xib in my project). These are just unknown errors for which xcode show error just in AppDelegate.h file
AppDelegate.h
#import <UIKit/UIKit.h>
#class ViewController;
#class SignInViewController;
#class StagesViewController;
#class ResultViewController;
#class myFacebook;
#interface AppDelegate : UIResponder <UIApplicationDelegate>{
myFacebook *myFB;
NSString *appVer;
}
+ (NSString*)Username;
+ (void)setUsername:(NSString*)newUser;
+ (NSString*)UserID;
+ (void)setUserID:(NSString*)newId;
#property (nonatomic, retain) myFacebook *myFB;
#property (strong, nonatomic) UIWindow *window;
#property (strong, nonatomic) UINavigationController *theNavigationController;
#property (strong, nonatomic) ViewController *viewController;
#property (strong, nonatomic) SignInViewController *signInViewController;
#property (strong, nonatomic) StagesViewController *stagesViewController;
#property (strong, nonatomic) ResultViewController *resultViewController;
#end
Any kind of help will be greatly appreciated, because I'm searching for these errors since last week but unable to solve it.
The problem is not in the AppDelegate.h that you posted. That file compiles just fine.
You need to figure out which .m file Xcode is trying to compile when it issues the errors. Go to the Log Navigator (View > Navigators > Show Log Navigator). Choose your latest build. It should have a red circle next to it because of the errors. Click on it to show the log for that build.
You should find a line in the list like “Compile AppDelegate.m” or “Compile ViewController.m” that lists the errors under it. That's the file that Xcode is trying to compile.
Now go to that file. Look at the top of the file, where your #import statements are. Check for stray characters that you might have accidentally entered.
If you don't find any stray characters there, go through each imported file. Look at the end of the file for stray characters, or a missing #end statement, or a missing semicolon, or a missing brace, or a missing parenthesis. Any of these problems will cause compiler errors that show up in the next imported file, or in the .m file.
If you're using a revision control system (like git or svn), use it to diff your files. Look for changes that don't make sense, at the top or end of your .h files or the top of your .m files. If you've checked in files while the build was broken, you'll need to diff against an older, working revision.
If you're not using a revision control system, now you know why you need to start using one ASAP.
See Rob Mayoff's answer above for the real problem: errant characters in a .m or .h file.
Just one thing to add to his reply: if you're not using version control, open up your favorite file browser, navigate to your source file tree, and sort the files by date. Start looking in the files you changed most recently.