skywise
skywise

Reputation: 49

Why am I seeing an ARC issue saying I did declare a method with a particular selector?

Guess it's a simple question, but after googling and reading in a lot of documents, i'm still stuck with a stupid error. So I guess, i have some understnding problems according to ARC ...

I'm trying to write my first Objective-C Program using the new ARC-Features. As I'm used to, i created two objects and try to call a method in the one object out of the other. I did this in old Xcode thousand times that way, but with ARC, it throws errors on me:

//ClassOne.h
@interface ClassOne : SPSprite 
{
    SPImage *stammImg;    
}   
-(void)methodToCall:(NSString*)msgString;   
@end

//ClassOne.m
-(void)methodToCall:(NSString*)msgString
{
   NSLog(@"called, thank you");
}

//ClassTwo.h
#import "ClassOne.h"

// somewhere in ClassTwo.m
ClassOne *myObject = [[ClassOne alloc] init];
[myObject methodToCall:@"hello"];

Easy, isn't it? But it doesn't work at all! What has changed in Method-Definition and Calling when making a new Project using ARC?

Compiler throws the Error:

Automatic Reference Counting Issue: error: receiver type 'SPSprite' for instance message does not declare a method with selector 'methodToCall:' [4]

Edit: Checked all the inputs about SPSprite or Upper-Case. All right. Guess what: If I deactivate ARC in build-settings, everything works fine...

Guess will be easy to answer for someone already coding using ARC...

Upvotes: 3

Views: 976

Answers (1)

zaph
zaph

Reputation: 112857

Nothing has changed in Method-Definition and Calling when making a new Project using ARC?

The problem in your test is probably SPSprite. If I change SPSprite to NSObject the code compiles and runs fine.

ARC relies on naming conventions. Although it makes no difference in this example naming conventions are that class names start with an upper case letter so classOne would be better as ClassOne.

Test:

@interface ClassOne : NSObject {
    NSObject *stammImg;
}

-(void)methodToCall:(NSString*)msgString;
@end

@implementation ClassOne
-(void)methodToCall:(NSString*)msgString {
    NSLog(@"called, thank you");
}
@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    ClassOne *myObject = [[ClassOne alloc] init];
    [myObject methodToCall:@"hello"];

    return YES;
}

NSLog output:

called, thank you

Upvotes: 3

Related Questions