I'm trying to compile my Objective-C application but it fails saying "Unknown type name 'OpenGLView'". Now I know what this means but the weird thing is I'm convinced I'm importing it just fine.
#import <Foundation/Foundation.h>
#import "OpenGLView.h"
#import "Frame.h"
#import "Mesh2.h"
#import "Vector2.h"
#import "StaticRigidBody.h"
#import "DynamicRigidBody.h"
#interface PhysicsApplicationController : NSObject {
Frame* frame;
OpenGLView* view;
}
It fails on line 11 of this sample. You can see I import it on line 2. The thing which I can't get my head around though is the same import works completely fine in this segment.
#import <UIKit/UIKit.h>
#import "OpenGLView.h"
#interface PhysicsAppDelegate : UIResponder <UIApplicationDelegate> {
OpenGLView* _glView;
}
Both source files for the two segments are in the same directory. I have no idea what is going on.
[EDIT]
Content of OpenGLView.h
#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
#include <OpenGLES/ES2/gl.h>
#include <OpenGLES/ES2/glext.h>
#import "PhysicsApplicationController.h"
#interface OpenGLView : UIView {
CAEAGLLayer* _eaglLayer;
EAGLContext* _context;
GLuint _colorRenderBuffer;
GLuint _positionSlot;
GLuint _colorSlot;
PhysicsApplicationController* _physicsController;
}
typedef struct {
float position[3];
float color[4];
} Vertex;
- (void)renderFrame:(Frame*)frame;
- (void)drawObjectsInFrame:(Frame*)frame;
- (void)setupVBOsWithVertices:(Vertex*)vertices Indices:(GLubyte*)indices;
- (void)setPhysicsController:(PhysicsApplicationController*)controller;
#end
Related
Here is my header file for Board:
#import "Game.h"
#import <Foundation/Foundation.h>
#interface Board : UIView
{
enum Piece;
}
- (void) setGame: (Game*) theGame; //<-- this is where the error is
typedef enum {X, O, NONE} Piece;
- (float)getSection;
#end
The compiler says "Expected a type" and has (Game*) underlined. What is the problem here?
Game.h:
#import <Foundation/Foundation.h>
#import "Board.h"
#interface Game : UIViewController
- (void)boardwasTapped:(int) row:(int) column;
#end
Don't import your header, but forward declare it. Import the Game header in Board.m
#class Game;
#interface Board : UIView {
...
}
...
#end
Also, are you sure the problem isn't with your enum? You are using it in your header before you declare it. You should declare it above (outside) the #interface block.
Board import game, and Game import Board. So you need to forward class Game in Board
#Class Game
I've created a file with sql methods and now this file is really large. I'd like to split it for best practice and implementation simplicity. So, categories.
I've created in xCode new objective-c categories file -> DBAccess+Generals.h (.m).
.h:
#import "DBAccess.h"
#interface DBAccess (Generals)
-(void)newMeth;
#end
.m
#import "DBAccess+Generals.h"
#import "DBAccess.h"
#implementation DBAccess (Generals)
-(void)newMeth
{
NSLog(#"New Meth");
}
#end
In DBAccess.h
#import <Foundation/Foundation.h>
#import <sqlite3.h>
#import "DBAccess+Generals.h"
#interface DBAccess : NSObject
{
NSString *databaseName;
}
#property(nonatomic,strong)NSString *databaseName;
DBAccess.m
#import "DBAccess.h"
#import "DBAccess+Generals.h"
#implementation DBAccess
#synthesize databaseName;
sqlite3* database=nil;
-(id)init
{
if ((self=[super init]))
{
//[self initializeDataBase];
databaseName=#"world_coins.db";
//firstVerDB=#"ac_ch_ver.1.0.db";
}
return self;
}
//Tones of methods
#end
Looks like the code is OK. Getting error "interface implementation not found for DBAccess". I've googled and stackoverflowed around, but the issues described, are not my case.
any help? Thank you in advance.
The problem is the cyclic import
#import "DBAccess+Generals.h" in DBAccess.h
#import "DBAccess.h" in DBAccess+Generals.h
If you remove the first one, the code compiles.
#import <Foundation/Foundation.h>
#import "Dropbox_Manager.h"
#interface FileSystemManager : NSObject {
NSFileManager *fileManager;
BOOL fileExisting;
BOOL contentIsEqual;
BOOL isWriteable;
Dropbox_Manager *dropBox_Manager; // Here Xcode shows the Error !!!!!
}
I don't get any other error in the project, but Xcode can't find the Type.
Replace
#import "Dropbox_Manager.h"
with
#class Dropbox_Manager;
Then add
#import "Dropbox_Manager.h"
to your FileSystemManager.m file
i'm having some weird compiler errors in objective-c:
iBody.h:18: error: ISO C++ forbids declaration of 'iObject' with no type
iObject.h
#import "iElement.h"
#import "CCSprite.h"
#import "iBody.h"
#interface iObject : iElement
{
iBody *body;
}
-(iObject*)initElement:(CGPoint)pos
withName:(NSString*)name
zIndex:(NSInteger)z
withImage:(NSString*)image;
-(void) addBody: (iBody*) body;
-(iBody*) getBody;
#end
iBody.h
#import "iObject.h"
#import "b2Body.h"
#interface iBody : NSObject
{
CGPoint position;
float angle;
b2Body *body;
iObject *parent;
}
-(iBody*) initElement: (CGPoint) pos
withAngle: (float) angle
withParent: (iObject*) el;
-(void) setBody: (b2Body*)bdy;
-(iObject*) getParent;
#end
can someone please explain why this is happening and how to fix it. The implementation of the classes have .mm extension.
Thanks!
This is because you have a circle include of header files.
See, you are including iBody.h in iObject.h and 'iObject.h' in iBody.h. So the compiler will see something like this:
#interface iBody : NSObject
{
CGPoint position;
float angle;
b2Body *body;
iObject *parent;
}
-(iBody*) initElement: (CGPoint) pos
withAngle: (float) angle
withParent: (iObject*) el;
-(void) setBody: (b2Body*)bdy;
-(iObject*) getParent;
#end
#interface iObject : iElement
{
iBody *body;
}
-(iObject*)initElement:(CGPoint)pos
withName:(NSString*)name
zIndex:(NSInteger)z
withImage:(NSString*)image;
-(void) addBody: (iBody*) body;
-(iBody*) getBody;
#end
As you can see iBody doesn't know about iObject when it is declined.
To resolve such situation you should just add string #class iObject; before #interface iBody: NSObject and remove include of iObject.h in iBody.h. But in implementation file iBody.m you should import iObject.h
It seems like you're in an import loop, since the headers of iBody and iObject are linking to one another. Typically in this situation I would consider the iObject to be of higher status and use the following in iBody.h:
// Replace the import to iObject.h with this:
#class iObject;
// Add the import back in iBody.mm
#import "iObject.h"
Now there is no import loop and only the implementation file of iBody actually links to iObject.h, and since no headers link to iBody.mm the issue is solved. Also, remember to rename the implementation files to .mm (Obj-C/C++) when working with Box2D, that gets me now and then :)
My project works fine on simulator but wouldn't build on real device after adding:
#synthesize extraView=_extraView;
It seems that this line somehow hides file header. Tried "Clean" - no change.
I've used #property and #synthesize many times before and haven't seen anything like this.
I'm planning to rewrite extraView handling but I'm asking just out of curiosity if someone has experienced similar error.
Platform:
XCode 4.0.1
4.2.1 Ipad
File header:
//
// MediaBook.h
// Dolphin
//
// Created by Handymood on 11-5-22.
// Copyright 2011 __Hanydmood__. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "SinglePage.h"
#import "LayerInfo.h"
#import "MediaBookXMLParser.h"
#import "GlobalSet.h"
#import "UIComponentBase.h"
#import "IndexPageInfo.h"
#import "IndexPage.h"
#import "TopBar.h"
#import "BottomBar.h"
#import "DolphinUIWebLayer.h"
#import "MediaBookBase.h"
#import "ColorUtil.h"
#import "DolphinUICategory.h"
#import "UICategoryUnit.h"
#import "ImageInfoBox.h"
#import "Gallery.h"
#import "Calendar.h"
#class SinglePage;
#class LayerInfo;
#class MediaBookXMLParser;
#class GlobalSet;
#class UIComponentBase;
#class IndexPageInfo;
#class IndexPage;
#class TopBar;
#class BottomBar;
#class DolphinUIWebLayer;
#class MediaBookBase;
#class ColorUtil;
#class DolphinUICategory;
#class UICategoryUnit;
#interface MediaBook : MediaBookBase <UIScrollViewDelegate>
{
UIImageLayer *backGroundImage;
UIView *bgView;
BottomBar *bottomBar;
DolphinUIWebLayer *webLayer;
DolphinUICategory *categoryLayer;
UIActivityIndicatorView *activityIndicator;
UIInterfaceOrientation preOrientation;
NSTimer *objQueMagTimer;
float previous_scroll_pos;
BOOL bar_status_hidden;
float top_bar_ori_y;
float bottom_bar_ori_y;
BOOL scroll_block_signal;
int screen_direction;//0:vertical 1:horizontal
BOOL webLayerOn;
BOOL categoryOn;
BOOL changingExtraView;
}
#property UIInterfaceOrientation preOrientation;
#property (nonatomic, retain) UIView *extraView;
-(void) initWithGlobalSet:(GlobalSet *) inGlobalSet;
-(void) initBook:(NSString *)configXmlAdd curOrientation:(UIInterfaceOrientation)interfaceOrientation;
-(void) initBookContent;
-(void) notificationSelector:(NSNotification *) notification;
-(void) statusBarAnimationTrigger;
-(void) layoutAdjustWithOrientation:(UIInterfaceOrientation)interfaceOrientation
orientaionType:(NSString *) inOrientationType;
-(void) closeCategoryLayer;
-(void) reset;
-(void) showExtraView:(NSString *)name;
-(void) hideExtraView;
#end
Screenshot of build errors:
I've used #property and #synthesize many times before and haven't seen any similar.
Adding following to interface declaration solved the problem:
UIView *_extraView;
Thanks to mja for the tip.