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

#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?).

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>

Where is NSTextField?

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

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.

Strange Delegate Protocol Declaration error?

So in a header file I have the following code:
#import <AudioToolbox/AudioToolbox.h>
#interface alertController:UIViewController <AVAudioPlayerDelegate>
{
AVAudioPlayer *player;
}
I have both the framework linked and It works just fine in another file within the same project, but I am getting the error that it cannot find the protocol declaration for "AVAudioPlayerDelegate", nor does it recognize the line AVAudioPlayer * audioPlayer because it is an unknown type name. Any ideas why this isn't working despite my import statement, including the framework, and the fact that it's working fine in another file?
AVAudioPlayer (and its delegate) come from AVFoundation, not AudioToolbox. Your other project probably imports <AVFoundation/AVFoundation.h> either through a separate included header file or through your PCH. You should replace that #import with
#import <AVFoundation/AVFoundation.h>

Why "error: expected specifier-qualifier-list before 'UITextView'" (but not for other view types!)

A question about specifier-qualifier-list has already been (asked) and answered but none of the anwsers given solve my problem.
My code is simple:
#import <UIKit/UIKit.h>
#interface TableCellWithTextView: UITableViewCell
{
#private
UITextView *theTextView;
}
#property (nonatomic, retain) UITextView *theTextView;
#end
But I get the compiler error "error: expected specifier-qualifier-list before 'UITextView'"
If I replace UITextView with UIView the error goes away. More oddly in my um.. in my view (no pun intended ;-)) is that I can also use any other view class without problem (UITextLabel, UIImageView, etc..)
But most bizarrely of all, elsewhere in my project, this compiles (and works):
#import <UIKit/UIKit.h>
#interface ToDoDetailTextViewEditCell : UITableViewCell
{
#private
UITextView *theTextView;
}
#property (nonatomic, retain) UITextView *theTextView;
#end
OK, people don't trouble yourselves. Things got weird for me as I dragged the files over to a brand new project and everything compiled. And ultimately weird when I deleted the old copies, dragged them back in from the new 'temp' project and everything compiled again.
So, no idea what the problem was but something must have got messed up. The files were part of a brand new folder structure I'd created by hand and I'd also been doing some refactoring, renaming files, so I guess some references somewhere had just got screwed up. I tried cleaning, many times, to no avail. What I didn't try actually was to restart Xcode (though I kept thinking to do it).
But egal. It works now.