Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trivial "+[NSTimer scheduledTimerWithTimeInterval:repeats:block:]: unrecognized selector" error

Tags:

cocoa

nstimer

I am banging my head against an odd error after a move to 10.12/Sierra and Xcode 8.1:

+[NSTimer scheduledTimerWithTimeInterval:repeats:block:]: 
     unrecognized selector sent to class 0x7fff78f1fa88

The most minimal code (default settings of create a new project) to reproduce this is:

//  AppDelegate.m
//

#import "AppDelegate.h"

@interface AppDelegate ()

@property (weak) IBOutlet NSWindow *window;
@property (strong, nonatomic) NSTimer * timer;
@end

@implementation AppDelegate

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
    self.timer = [NSTimer scheduledTimerWithTimeInterval:10 
                           repeats:YES 
                             block:^(NSTimer * _Nonnull timer) 
   {
        NSLog(@"Ping from %@", timer);
    }];
}

The linking includes the (Core)Foundation classes and 'all_load'. Must be something totally trivial - but fail to what it is.

Any and all help appreciated.

Thanks,

Dw.

like image 990
Dirk-Willem van Gulik Avatar asked Nov 10 '16 07:11

Dirk-Willem van Gulik


1 Answers

+[NSTimer scheduledTimerWithTimeInterval:repeats:block:] is an iOS 10.0+ method. Are you maybe trying to run it on iOS 9.x?

https://developer.apple.com/reference/foundation/nstimer/2091889-scheduledtimerwithtimeinterval?language=objc

like image 110
Alessandro Mulloni Avatar answered Oct 22 '22 01:10

Alessandro Mulloni