Objective-c subclassing gives linking error - objective-c

I'm trying to port a game to iOS but I'm having a problem. I have a class called CKSprite with the following method:
- (id)initWithFile:(NSString *)fileName effect:(GLKBaseEffect *)effect
{
if ((self = [super init]))
{
//some stuff
}
return self;
}
I then have a subclass called CKPLayer (it has no other methods or properties at the moment other than what it inherits:
#property (strong) CKPlayer *player1;
But when I try to initialise it using the parent method:
self.player1 = [[CKPlayer alloc] initWithFile:#"Images/parrot.png" effect:self.effect];
I get this error:
Undefined symbols for architecture i386:
"_OBJC_CLASS_$_CKPlayer", referenced from:
objc-class-ref in CKViewController.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
This is my first time trying to do anything like this so I've probably done something stupid.
Any help will be greatly appreciated.
#import "CKSprite.h"
#interface CKPlayer : CKSprite
#end

The linker is missing the implementation for the class CKPlayer. Maybe you just forgot to implement it since it has "no other methods or properties at the moment", in that case just add a file which should look like:
#import "CKPlayer.h"
#implementation CKPlayer
#end
and ld should be happy

Related

Undefined symbols "_OBJC_CLASS_$_" error

My project is written in ApplescriptObjC and Objective-C.
I have an NSTabViewDelegate, which must be written in ObjC:
#import <Cocoa/Cocoa.h>
#import "MSItems.h"
#interface MSTabView : NSTabView<NSTabViewDelegate>
- (void)tabView:(NSTabView *)tabView willSelectTabViewItem:(NSTabViewItem *)tabViewItem;
#end
#implementation MSTabView
- (void)tabView:(NSTabView *)tabView willSelectTabViewItem:(NSTabViewItem *)tabViewItem {
if ([[tabViewItem identifier] intValue] == 1) {
[MSItems myMethod];
}
}
#end
MSItems class is written in ApplescriptObjC, but I created a header file, which contains only the method I need to be called by other classes.
#import <Cocoa/Cocoa.h>
#class MSItems;
#interface MSItems : NSObject
+ (void) myMethod;
#end
In the ASObjC class i have:
script MSItems
property parent : class "NSObject"
on myMethod()
--stuff
end myMethod
end script
But the app doesn't compile and I get the error:
Undefined symbols for architecture x86_64:
"_OBJC_CLASS_$_MSItems", referenced from:
objc-class-ref in MSTabView.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

[objective-c]How do I send one method a message from another .m file

I am trying to take a picture from my iPad app, using code I have found on the internet. I have this method:
- (BOOL) startCameraControllerFromViewController: (UIViewController*) controller
usingDelegate: (id <UIImagePickerControllerDelegate,
UINavigationControllerDelegate>) delegate {
in a file called CameraViewController.m.
In CameraViewController.h, I have this definition:
#interface CameraViewController : UIViewController
+ (BOOL) startCameraControllerFromViewController: (UIViewController*) controller
usingDelegate: (id <UIImagePickerControllerDelegate,
UINavigationControllerDelegate>) delegate;
#end
I am trying to call it from this method which is in ClientSetupViewController.m:
- (void) captureImage {
[startCameraControllerFromViewController: self usingDelegate: self];
}
I'm getting an error saying
Use of undeclared identifier startCameraControllerFromViewController
I have #import "CameraViewController.h" in CLientViewController.h
I'm totall lost! I thought I had everything defined correctly, but I guess not. What is wrong with my code?
UPDATE: getting this error now after changing code to call instance:
Undefined symbols for architecture armv7:
"_OBJC_CLASS_$_CameraViewController", referenced from:
objc-class-ref in ClientSetupViewController.o
anon in CameraViewController.o
l_OBJC_$_CATEGORY_CameraViewController_$_CameraDelegateMethods in CameraViewController.o ld: symbol(s) not found for architecture
armv7 clang: error: linker command failed with exit code 1 (use -v to
see invocation)
Please go through an Objective-C tutorial once more before making The Best iOS App Ever (TM) - you're missing fundamentals of the syntax.
One, you're using the - and + method prefixes inconsistently. Decide whether it should be a class (+) or instance (-) method and add the prefix accordingly - and use the same prefix both in the declaration in the header file and in the definition (in the implementation file).
Once you have fixed this, you have to send the message to the class itself if you defined a class method or to an instance if you have an instance method. Example using a class method:
[CameraViewController startCameraControllerFromViewController:self usingDelegate:self];
Example using an instance method:
[someOtherViewController startCameraControllerFromViewController:self usingDelegate:self];
assuming that someOtherViewController is a valid instance of CameraViewController.
If startCameraControllerFromViewController:usingDelegate: is indeed a class function (as indicated by the +), then the way to call the function would be:
[CameraViewController startCameraControllerFromViewController: self usingDelegate: self]
A message is sent to an object, or a class. In your code, you have just the message name in the message call [ ], with no indication of where this message should be sent to.

Pass information between classes

I'm fairly new to Objective-C and I'm running into a problem.
I need to pass some information from one viewcontroller to another. I've tried a number of methods and either get build error or don't make enough sense.
Here is what I have so far.
In the second view controllers h file:
#property (nonatomic) NSString *OwnerID;
The data should go into this property.
In the first view controllers m file:
MoreByUserViewController *moreimg =[[MoreByUserViewController alloc] init];
moreimg.OwnerID = ImageOener;
I think this isn't correct but don't know what else to write.
The clang error I get:
duplicate symbol _m_PageCounter in:
/Users/ianspence/Library/Developer/Xcode/DerivedData/Pickr-dohtanjxfozprjbuwlphjbhvxttm/Build/Intermediates/Pickr.build/Debug-iphonesimulator/Pickr.build/Objects-normal/i386/PKRViewController.o
/Users/ianspence/Library/Developer/Xcode/DerivedData/Pickr-dohtanjxfozprjbuwlphjbhvxttm/Build/Intermediates/Pickr.build/Debug-iphonesimulator/Pickr.build/Objects-normal/i386/MoreByUserViewController.o
ld: 1 duplicate symbol for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Is it a circular reference? check out your header files.
Your problem is something else, now you are getting error for _m_PageCounter. I think twice you put m_PageCounter or used same variable in two different headers..
in .h file just declare #class MoreByUserViewController. and add header file of MoreByUserViewController in .m fie.
#interface MoreByUserViewController : UIViewController
{
NSString *mOwnerID;
}
#property(nonatomic, retain) NSString *OwnerID;
-(id)initWithID:(NSString*)inId;
#end
#implementation MoreByUserViewController
#synthesize OwnerID = mOwnerID;
-(id)initWithID:(NSString*)inId
{
if(self = [super init])
{
self.OwnerID = inId;
}
return self;
}
#end
//Somewhere else in code
MoreByUserViewController *moreimg =[[MoreByUserViewController alloc] initWithID:#"AnyIdOnUrWish"];
duplicate symbol _m_PageCounter means you have a constant or variable or function named m_PageCounter defined in two places. Specifically, in PKRViewController.m and MoreByUserViewController.m.
Your options:
Delete one of them.
Rename one of them.
Declare one of them static so they won't be visible outside of that source file.

Getting Strange Error Running Objective C Code

My project have no visible error but when i try to run it gives following error
Undefined symbols for architecture i386:
"_OBJC_CLASS_$_ConcreteScreen", referenced from:
objc-class-ref in ViewController.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I am using my ContactScreen class in ViewController.m
i tried by #class ContactScree and #import "ContactScreen.h"
and in my ViewController i am using it as [ContactScreen myMethod];
when i comment out this line it work fine but now it is giving compile time error :(
yesterday it was wroking fine
here is my code
#import "ViewController.h"
#import "ConcreteScreen.h"
#interface ViewController ()
#end
#implementation ViewController
-(IBAction)btnContactPress:(id)sender{
NSLog(#"Contact Screen");
ConcreteScreen *coontact = [[ConcreteScreen alloc]init];
}
You confused ConcreteScreen and ContactScreen and compiler told you that it isn't aware about ConcreteScreen
Be sure your .m file is included in the project. It's possible to create it, use the header and all but it doesn't go into the build. Also it needs to be in the target.

GCDAsyncUdpSocket does not compile for iOS

I use this library: https://github.com/robbiehanson/CocoaAsyncSocket
There are examples for TCP on the iphone but not UDP. I think that everything should be just the same. Here is my code:
#import <UIKit/UIKit.h>
#class GCDAsyncUdpSocket;
#interface ThirdViewController : UIViewController
{
GCDAsyncUdpSocket *udpSocket;
}
.m:
#import "ThirdViewController.h"
#import "DDLog.h"
#import "DDTTYLogger.h"
#import "GCDAsyncUdpSocket.h"
static const int ddLogLevel = LOG_LEVEL_VERBOSE;
#implementation ThirdViewController
- (void)viewDidLoad
{
[DDLog addLogger:[DDTTYLogger sharedInstance]];
udpSocket = [[GCDAsyncUdpSocket alloc] initWithDelegate:self delegateQueue:dispatch_get_main_queue()];
}
But when compiling I get the errors:
Undefined symbols for architecture i386: "_OBJC_CLASS_$_DDLog",
referenced from:
objc-class-ref in ThirdViewController.o "_OBJC_CLASS_$_DDTTYLogger",
referenced from:
objc-class-ref in ThirdViewController.o "_OBJC_CLASS_$_GCDAsyncUdpSocket",
referenced from:
objc-class-ref in ThirdViewController.o ld: symbol(s) not found for architecture i386
What is wrong? Examples from the library compiled without errors.
You have to link CFNetwork.framework or if have it you're propably working on Automatic Reference Counter, turon off ARC for GCDAsyncUdpSocket using -fno-objc-arc
(Build Phases >> Link Binary With Libraries) Add CocoaLumberjack as optional dependency.