Error: expected specifier-qualifier-list before 'QTVisualContextRef' - objective-c

I am currently getting this error message in my header code, and I'm not sure as to why:
"Error: expected specifier-qualifier-list before 'QTVisualContextRef'"
#import <Cocoa/Cocoa.h>
#import <QTKit/QTKit.h>
#import <OpenGL/OpenGL.h>
#import <QuartzCore/QuartzCore.h>
#import <CoreVideo/CoreVideo.h>
#interface MyRecorderController : NSObject {
IBOutlet QTCaptureView *mCaptureView;
IBOutlet NSPopUpButton *videoDevicePopUp;
NSMutableDictionary *namesToDevicesDictionary;
NSString *defaultDeviceMenuTitle;
CVImageBufferRef mCurrentImageBuffer;
QTCaptureDecompressedVideoOutput *mCaptureDecompressedVideoOutput;
QTVisualContextRef qtVisualContext; // the context the movie is playing in
// filters for CI rendering
CIFilter *colorCorrectionFilter; // hue saturation brightness control through one CI filter
CIFilter *effectFilter; // zoom blur filter
CIFilter *compositeFilter; // composites the timecode over the video
CIContext *ciContext;
QTCaptureSession *mCaptureSession;
QTCaptureMovieFileOutput *mCaptureMovieFileOutput;
QTCaptureDeviceInput *mCaptureDeviceInput;
}
#end
In the examples I have seen through other code (e.g. Cocoa Video Tutorial) I have not seen any difference in their code to mine. If anyone would be able to point out as to how this error could have occurred that would be great.
Thanks heaps! :)

If you are compiling as a 64-bit application, QTVisualContextRef is not available to you. You'll need to compile the application as 32-bit.
Apple hasn't fully fleshed out QTKit to be 64-bit quite yet...

That's a GCC error and it means the token QTVisualContextRef is not known to the compiler. It's a rather poor error message indeed. You need to add the correct #import that will teach the compiler about this type. It's part of the QuickTime framework, so you probably want
#import <QuickTime/QuickTime.h>

Related

Appcelerator iOS Module with OpenCV - OpenCV's camera won't open

So, I am developing an Appcelerator iOS Module which uses OpenCV to do some image processing with the camera.
The thing is, the camera won't open at all. I read the official OpenCV example, followed the steps (of course, had to adapt things to be used as an Appc Module), also followed the iOSModuleQuickStart from the Appcelerator Wiki. I thought I did it right, except that it just doesn't work.
This is my .h View class from the Module:
#import "TiUIView.h"
#import <Foundation/Foundation.h>
#import <opencv2/videoio/cap_ios.h>
#import <UIKit/UIKit.h>
using namespace cv;
#interface ComIosopencvmoduleTestView : TiUIView<CvPhotoCameraDelegate>
{
UIImageView *imageView;
CvPhotoCamera *photoCamera;
}
#property (nonatomic, retain) CvPhotoCamera* photoCamera;
#end
This is the implementation of it (.mm):
#import "ComIosopencvmoduleTestView.h"
#import "TiUtils.h"
// some other imports....
#implementation ComIosopencvmoduleTestView
#synthesize photoCamera;
#pragma mark - UI Actions
- (void)initializeState
{
self.photoCamera = [[CvPhotoCamera alloc] initWithParentView:imageView];
self.photoCamera.delegate = self;
self.photoCamera.defaultAVCaptureDevicePosition = AVCaptureDevicePositionBack;
self.photoCamera.defaultAVCaptureSessionPreset = AVCaptureSessionPresetPhoto;
self.photoCamera.defaultAVCaptureSessionPreset = AVCaptureSessionPreset352x288;
self.photoCamera.defaultAVCaptureVideoOrientation = AVCaptureVideoOrientationPortrait;
[self.photoCamera start];
// The instantiation and the call to start method, should do the trick, but it doesn't
}
#end
And, this is how I call it on JS, from Appcelerator Studio:
var VWindow = Ti.UI.createWindow({});
var VView = VItire.createView({});
var VItire = require('com.iosopencvmodule.test');
VWindow.add(VView);
VWindow.open();
This code, according to what I understood from both Tutorials, OpenCV and Appcelerator, should be enough to open the Camera as the App is launched.
Please, what could possibly be wrong? I am going mad with this. Thanks in advance!
Please help!

iOS 8 Expected a type

I have the UIScrollViewSlidingPages and the SSPullToRefresh libraries in a lot of projects, but suddenly, I'm getting this weird errors in this new iOS 8 project.
#import <Foundation/Foundation.h>
#interface TTSlidingPageTitle : NSObject
-(id)initWithHeaderText:(NSString*)headerText;
-(id)initWithHeaderImage:(UIImage*)headerImage;
//The title text to go in the nav bar
#property(strong, nonatomic) NSString *headerText;
//An image to use in the nav bar (if you set this, the title text will not be used)
#property(strong, nonatomic) UIImage *headerImage;
#end
This line is getting the "Expected a Type" error:
-(id)initWithHeaderImage:(UIImage*)headerImage;
And this line is getting the "Unknown type name UIImage" error:
#property(strong, nonatomic) UIImage *headerImage;
If you check the docs for UIImage you'll see it's in UIKit, not Foundation. The docs are now all targeted at Swift, which is somewhat annoying, but you'll see the import statement in the docs is specified as
#import UIKit;
which you need at the top of your file (no need for the Foundation import either).
Sometimes projects include this import statement in a precompiled header file (pch). This should be referenced in Build Settings->Prefix Header, or it won't be used in compilation.

CLLocation can't be found even though <CoreLocation/CoreLocation.h> is imported

#import <Foundation/Foundation.h>
#import <CoreLocation/CoreLocation.h>
#interface SomeClass : NSObject
{
CLLocation *location;
//...
}
//...
Code seems okay, right?
But I still get "Unknown type name 'CLLocation'", even though CoreLocation.framework is imported to "Link Binary with Libraries" and CoreLocation.h is imported.
This error occured after I added a new target to the project - "Cocoa Touch Unit Testing Bundle". CoreLocation.framework is imported to this target, too.
Removing and adding the framework back is the best solution through which i solved a same problem.Also make sure you have added framework to unit test project.

Objective-C Categories not being recognized?

Well, this is quite a weird issue. (I just hope it has something to do with my not-playing-that-much-with-Cocoa-for-a-while, or else...)
So, the issue is quite straightforward :
I'm using Xcode 4.3.3 (a very simple test project - 10.7 SDK - no ARC)
I'm creating a Category on some Class (e.g. NSProgressIndicator)
I'm including the appropriate header file
When trying to use any of my Category's methods (however, it still shows up in the dropdown of available commands), I'm getting an error :
[NSProgressIndicator start]: unrecognized selector sent to instance
0x7f9f4b91a0a0
The code (as an example - it has happened with other (100-times tested) categories):
#import <Foundation/Foundation.h>
#interface NSProgressIndicator (NSProgressIndicator_Functions)
- (void)start;
- (void)stop;
#end
#import "NSProgressIndicator+Functions.h"
#implementation NSProgressIndicator (NSProgressIndicator_Functions)
- (void)start
{
[self setHidden:NO];
[self startAnimation:nil];
}
- (void)stop
{
[self setHidden:YES];
[self stopAnimation:nil];
}
#end
Any ideas?
To expand my comment into a real answer:
Make sure the category's implementation (.m) file is included in your target's Compile Sources build phase. Importing the header is enough to tell the compiler that there is a category on NSProgressIndicator which adds a -start method. Unless the category's implementation is actually compiled and linked into the finished binary (or the method implementation is added at runtime, etc), NSProgressIndicator won't actually respond to the start message at runtime. Because of Objective-C's dynamic message send behavior, there's no way the compiler can tell at compile time whether or not NSProgressIndicator is actually going to respond to that message, which is why you don't get a warning or an error.

Objective-C header file not recognizing custom object as a type

I'm working on a game for iPad using cocos2d which involves a board filled with different types of tiles. I've created a custom class called Tile as a general template for tiles and a few subclasses of Tile which have different properties and methods. I've also created a class called Board which, among other things, keeps track of the locations of all the tiles using a special coordinate system.
For some reason, in the Board class, the compiler doesn't seem to be recognizing Tile as a type of object, even though I've added #import "Tile.h" at the top of the file.
Here's the relevant code (just ask if there's other parts of the code you want to see):
Tile.h
#import <Foundation/Foundation.h>
#import "cocos2d.h"
#import "Board.h"
#interface Tile : NSObject
-(void) updateNeighbors;
#property (nonatomic, retain) CCSprite* sprite;
#property (assign) CGPoint coords;
#property (assign) CGPoint positionInPoints;
#property (nonatomic, retain) NSMutableArray *neighbors;
#end
Board.h
#import <Foundation/Foundation.h>
#import "cocos2d.h"
#import "Tile.h"
#interface Board : NSObject
+(Board*)sharedBoard;
- (void) putTile: (Tile*) tile AtIndex: (CGPoint) index; //<-- error here!
- (void) replaceTileAtIndex: (CGPoint) index1 WithTileAtIndex: (CGPoint) index2;
- (Tile*) tileAtIndex: (CGPoint) index; //<-- error here!
- (void) populate;
#property (nonatomic, retain) NSMutableArray *tiles;
#property (nonatomic, retain) NSString *type;
#property (assign) CGPoint size;
#end
This code will not even build and I'm getting the following error where indicated:
Expected '(' before 'Tile'
If I change the type from (Tile*) to (NSObject*), it fixes the error, which leads me to believe that Tile is not being recognized as a type of object.
I've searched via Google and this site and cannot figure out why this is happening.
Update
Dumb mistake; easy to fix.
As you all have pointed out the problem is that the two header files are importing each other, which is not allowed. For now, I've fixed the problem by moving the #import "Board.h" statement to Tile.m, since it isn't needed in the header file. Later on, if I decide to use Board in the Tile.h file I will use forward referencing (#class Board;), as a few of you suggested.
Thanks again!
This is a classic problem with headers importing headers. You have a circle here: Tile.h is importing Board.h, which imports Tile.h. This confuses the compiler -- it gets stuck in a loop.
You solve this by not importing headers into headers. You still need to let the compiler know about Tile, however. In Board.h, make a "forward declaration" of the class:
#import <Foundation/Foundation.h>
#import "cocos2d.h"
#class Tile; // Dear compiler,
// Tile is a class that I will need to refer
// to in this file. Please consider it to be a
// type; I promise it'll be defined at runtime.
// Sincerely, stephenalexbrowne
#interface Board : NSObject
//etc.
This assures the compiler that there is a class called Tile that will exist at runtime; you can then refer to that name in the remainder of your header. In your implementation for Board, you import Tile.h. That will let the compiler see the methods and properties associated with the Tile class where they are needed.
Likewise, move the #import "Board.h" into Tile.m. Since you aren't referring to the Board class in Tile.h, you don't need to make a forward declaration.
In general, it is best to import your class headers only into the implementation files where they are needed. Framework headers, since they will never cause a cycle with your code, can and -- because you need to refer to many of the classes declared in them -- should be imported into your headers.
Two files cannot import each other. You need to move the import directives to the implementation files, and instead just forward-declare the classes in the headers (e.g. #class Tile; in Board.h).
The reason circular imports don't work is because #import literally includes the text from the imported file in-place. But it also ensures that the text from a file will only be included once, in order to avoid duplicate declarations. So when Tile.h says that the text from Board.h needs to go before it, and Board.h says the text from Tile.h needs to go before it, there's literally nothing the compiler can do — one of them needs to go first, and that file is going to complain because it was expecting the other one to already be there.
This may not be the problem, but what happens if you remove the "#import "Board.h"" from the Tile.h file. You might have a problem with circular referencing