0

我正在尝试将“CodeRunner”用作Objective-C游乐场,但我正在尝试向该类添加一个新方法:

#import <Foundation/Foundation.h>

int main(int argc, char *argv[]) {


    @autoreleasepool {
    }
}

-(void)printSomeThing {
        NSLog("printing someThing")
}

我收到此错误:

Untitled.m:10:1: error: missing context for method declaration
-(void)printSomeThing {
^
1 error generated.

你们中的任何人都知道如何修复此错误吗?

我会非常感谢你的帮助。

4

1 回答 1

0

这就是我一直在寻找的:

#import <Foundation/Foundation.h>


NS_ROOT_CLASS
@interface MyClass
-(void)printSomthing;
@end

@implementation MyClass

-(void)printSomthing{
    NSLog(@"it work!!!");
}
@end


int main(int argc, char *argv[]) {


    @autoreleasepool {
        [MyClass printSomthing];
    }
}
于 2018-09-24T17:08:36.737 回答