CodeRunner:error: missing context for method declaration

157 views Asked by At

I'm trying to use "CodeRunner" as Objective-C playground but I'm trying to add a new method to the class:

#import <Foundation/Foundation.h>

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


    @autoreleasepool {
    }
}

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

I'm getting this error:

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

Any of you knows how fix this error?

I'll really appreciate your help.

1

There are 1 answers

0
user2924482 On

This is what I was looking for:

#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];
    }
}