I am stumped, im not very good with Objective-C yet, and I have been following tutorials until now.
I have decided to add all the functions I use in multipul views in one “CommonClass” I have called GeneralHelper.
When trying to call my function im getting the following error:
Instance method’-convertPoint:’ not found(return type defaults to
‘id’)
Below is my code:
My GeneralHelper.h lookslike this:
#import
@interface GeneralHelper : NSObject
@end
GeneralHelper* gHelper;
My GeneralHelper.m looks like this:
#import "GeneralHelper.h"
#import "WhackGame.h"
#import "SimpleAudioEngine.h"
#import "Settings.h"
@implementation GeneralHelper
-(CGPoint)convertPoint:(CGPoint)point {
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
return ccp(32 + point.x*2, 64 + point.y*2);
} else {
return point;
}
}
@end
Inside my Initialize method I have:
gHelper = [[GeneralHelper alloc] init]; //First, we create an instance of GeneralHelper
and im trying to call it like:
mole1.position = [gHelper convertPoint:ccp(85, 85)];
Any ideas?
Thanks
You didn’t declare the method
convertPoint:in your@interfacelike this:Also, if you’re trying to have one shared instance of GeneralHelper, that’s not the way to do it. Instead you should have a class method that returns an instance.
Then in your implementation:
And then wherever you need it:
Alternatively you could simply use class methods:
The implementation is the same as before, but with a + instead of a – sign. In this case you don’t need the
sharedHelpermethod and can simply call it like this: