选择器OpenDevice

时间:2015-07-24 00:08:12

标签: objective-c macos exception crash

我正在为OSX开发Objective-c中的应用程序。

我已经编写了第一堂课,并尝试在我的MainThread中调用此类。

构建成功但应用程序崩溃

DeviceManager.h

#import <Foundation/Foundation.h>

@interface DeviceManager : NSObject

+(void)DeviceManager:OpenDevice;

@end

DeviceManager.m

#import "DeviceManager.h"

@implementation DeviceManager

- (id)init{
    self = [super init];
    if(self){
        NSLog(@"Init");
    }
    return self;
}

+ (void)DeviceManager:OpenDevice {
    NSLog(@"Opening Device");
}

@end

main.m正在调用它:

#import "DeviceManager.h"


int main(int argc, const char * argv[]) {
    [DeviceManager OpenDevice];
    return NSApplicationMain(argc, argv);
}

在构建时,我没有知道选择器OpenDevice的类方法

THX SEB

1 个答案:

答案 0 :(得分:0)

#import <Foundation/Foundation.h>

@interface DeviceManager : NSObject

+ (void) openDevice;

@end

DeviceManager.m

#import "DeviceManager.h"

@implementation DeviceManager

+ (void) openDevice {
    NSLog(@"Opening Device");
}

@end

的main.m

#import "DeviceManager.h"

int main(int argc, const char * argv[]) {
    [DeviceManager openDevice];
    return NSApplicationMain(argc, argv);
}

以上对我有用。 DeviceManager:OpenDevice是什么意思?因为除非它是一种定义方法的新方法,否则就是胡言乱语。看起来你想要一个名为openDevice的设备管理器的类方法...所以使用+ (void) openDevice {...}