Krystian
Krystian

Reputation: 3423

Why can't I call object methods from AppDelegate? No known class method for selector

I have a DataHandler class which acts like a singleton, and it has sharedHandler object method. I use it throughout the whole project, but for some reason, I can't use it in AppDelegate.

DataHandler.h

    #import <Foundation/Foundation.h>

    @interface DataHandler : NSObject

    + (id)sharedHandler;
    - (void)logout;
    @end

DataHandler.m

#import "DataHandler.h"

/**
 * Singleton static method
 * @return singleton instance
 */
+ (id)sharedHandler {
    static DataHandler *sharedHandler = nil;
    @synchronized (self) {
        if (sharedHandler == nil)
            sharedHandler = [[self alloc] init];
    }
    return sharedHandler;
}

-(void) logout {
    // ...
}


@end

AppDelegate.m

#import "AppDelegate.h"
#import "DataHandler.h"

@implementation AppDelegate {

- (void)applicationWillResignActive:(UIApplication *)application {
    [[DataHandler sharedHandler] logout];
}

@end

I keep getting:

Error: no known class method for selector 'sharedHandler`
Error: no known instance method for selector 'logout'

What is the cause of this behavior?

Upvotes: 2

Views: 353

Answers (1)

Lily Ballard
Lily Ballard

Reputation: 185821

You have two files named DataHandler.h and the import in AppDelegate.m is picking up the wrong file. Note that it may be picking up a file that's not actually in your project, as long as it's in the folder on disk.

Upvotes: 3

Related Questions