JoshDG
JoshDG

Reputation: 3931

iOS: xCode not recognizing new class methods

For some reason new methods that I add to a custom NSObject class aren't being recognized in other files that import the class. The old ones are still being autofilled, but the new ones get a "no known class method for selector". All methods in the class are defined as class methods (+).

I've cleaned and tried rebuilding, and I've tried restarting xCode. I can't figure out whats wrong. Anyone experience this before?

@interface SongMethods : NSObject

+(NSMutableArray *)asdf;

And then to call it

#import "SongMethods.h"

@interface HomeViewController ()
@property ViewType billboardType;

@end

@implementation HomeViewController

-(void)someMethod
{
[SongMethods asdf];
}

Upvotes: 1

Views: 2639

Answers (3)

JoshDG
JoshDG

Reputation: 3931

The file was referenced from duplicate locations for some reason, and the one being imported in the other classes was not the same as the one I was editing in the navigator.

Upvotes: 4

juniperi
juniperi

Reputation: 3773

To create class method, you need to first introduce that method in your .h file:

MyClass.h

@interface MyClass : NSObject

// Note: + sign is for class method and - sign for instance method
+ (BOOL)returnYesPlease;

@end

Then add implementation of your method in .m file:

MyClass.m

@implementation MyClass

+ (BOOL)returnYesPlease {
    return YES;
}

@end

To use class method in MyClass, you need to import header file first in .h file:

MyOtherClass.h

#import "MyClass.h"

@interface MyOtherClass : NSObject

@end

To call that class method in .m file:

@implementation MyOtherClass

- (void)doSomething {
    BOOL yesVar = [MyClass returnYesPlease];
}

@end

Upvotes: 0

Maxthon Chan
Maxthon Chan

Reputation: 1189

You can try remove the entire project derived data folder.

Upvotes: 0

Related Questions