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

♀尐吖头ヾ 提交于 2019-12-07 06:04:24

问题


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.


回答1:


+[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



来源:https://stackoverflow.com/questions/40521799/trivial-nstimer-scheduledtimerwithtimeintervalrepeatsblock-unrecognized

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!