I'm starting with Objective-C and I have a problem.
The compiler is giving me this error message:
Semantic Issue: Use of undeclared identifier
And this is the main.m code:
#import <UIKit/UIKit.h>
#import "HMJAppDelegate.h"
int main(int argc, char *argv[]) {
#autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([HMJAppDelegate class]));
}
}
This error is in the main.m file.
How can I fix the problem?
Related
i have an Object_Info.h (contains the interface declaration) and Object_Info.m (contains some not all method implementations) files in the same directory as my main.m.
in main.m
#import <Foundation/Foundation.h>
#import "Object_Info.h"
int main(int argc, const char * argv[]) {
#autoreleasepool {
error thrown here -> use of undeclared identifier 'tempObjInfo'
(Object_Info*) tempObjInfo = [[Object_Info alloc] init];
}
return 0;
}
any ideas as to why the error is there? user of undeclared identifier 'tempObjInfo'
I've tried (Object_Info*) tempObjInfo = [Object_Info new] as well with no success.
Thanks!
You didn't declare the identifier. You should declare it like...
Object_Info *tempObjInfo = [[Object_Info alloc] init];
... or if the tempObjInfo symbol is declared somewhere globally you will need to include the header where it is being declared.
I have the following code:
#import <Foundation/Foundation.h>
#import <Cocoa/Cocoa.h>
#import </usr/local/Cellar/glew/1.12.0/include/GL/glew.h>
#import </usr/local/Cellar/glfw2/2.7.9/include/GL/glfw.h>
int main(int argc, const char * argv[])
{
#autoreleasepool
{
if(!glfwInit())
{
exit(EXIT_FAILURE);
}
}
return 0;
}
I get the following errors when compiling: glew.h User-defined Issue Gltypes.h included before glew.h Modules Issue Declaration of PFNGLCOPYTEXSUBIMAGE3DPROC must be imported from module 'OpenGL.GL3' before it is required
There are another 19 errors that are all semantic errors. Does anyone know how to fix this?
As it turned out I didn't properly compile the library files.
i'm building a SpriteBuilder project and getting the error of:
" * Assertion failure in int UIApplicationMain(int, char **, NSString *, NSString *)(), /SourceCache/UIKit_Sim/UIKit-2903.23/UIApplication.m:2380
Unable to instantiate the UIApplication subclass instance. No class named NSApplication is loaded."
For the main.m code of:
#import <UIKit/UIKit.h>
int main(int argc, char *argv[]) {
#autoreleasepool {
int retVal = UIApplicationMain(argc, argv, nil, #"AppController");
return retVal;
}
}
What's the cause?
XCode is referring to the wrong info.plist file. In Build Settings, the info.plist path should be "Source/Resources/Info.plist" instead of "$(SRCROOT)/Source/libs/cocos2d-iphone/external/Chipmunk/xcode/main-Info.plist". Changing the path fixed it.
Just starting out with Objective C so please be gentle. I've got a class as follows:
Card.h
#import <Foundation/Foundation.h>
#interface Card : NSObject
#property (nonatomic) NSUInteger x;
-(NSUInteger) getNum;
#end
Card.m
#import "Card.h"
#implementation Card
-(NSUInteger) getNum {
return self.x;
}
#end
main.c
#include <CoreFoundation/CoreFoundation.h>
#include "Card.h"
int main(int argc, const char * argv[])
{
return 0;
}
When I compile, I get a load of errors, first one is:
NSObjCRuntime.h: Parse Issue: Expected identifier or '('.
I know this is something stupid - just hoping somebody here can spot what i'm doing wrong.
Are you actually compiling this with an Objective C compiler? The traditional extension to instruct GCC and clang to use ObjC is .m (not .c).
I've dived into learning Objective-C and hit a little snag in when calling a method. Here's my simple code snippets:
Player.h code snippet:
#interface Player : NSObject{
}
-(void) performAction;
-(int) addNumber:(int) a toNumber:(int) b;
#end
Player.m code snippet:
#implementation Player
-(void)performAction{
NSLog(#"Here it is!");
}
-(int)addNumber:(int)a toNumber:(int)b{
return a+b;
}
#end
Calling method from main.m:
int val = [playerOne addNumber:(int)3 toNumber:(int)3];
In the above line of code, i keep getting an 'Expected expression' error.
Any ideas ?
This code works for me.
Player.h
#import <Foundation/Foundation.h>
#interface Player : NSObject
- (void)performAction;
- (int)addNumber:(int)a toNumber:(int)b;
#end
Player.m
#import "Player.h"
#implementation Player
- (void)performAction {
NSLog(#"Here it is!");
}
- (int)addNumber:(int)a toNumber:(int)b {
return a+b;
}
#end
main.m
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
#import "Player.h"
int main(int argc, char *argv[])
{
#autoreleasepool {
Player *playerOne = [Player new];
int val = [playerOne addNumber:(int)3 toNumber:(int)3];
NSLog(#"%d", val);
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}