Why am I allowed to write and use methods in implementations that are not declared in the header file in Objective-C?

@interface SomeClass : NSObject
{
}
@end

@implementation SomeClass
-(void) awesomeMethod600
{
}
@end

There is no error and awesomeMethod600 is working.

+3
source share
2 answers

Method declarations in class interfaces exist for the compiler (to suppress warnings), since the method is searched in Objective-C at run time, not compile time.

+7
source

Perspx is right.

Try creating this in Xcode:

@implementation SomeClass
-(void)awesomeMethod {
    [self notAwesomeMethod];
}    

-(void)notAwesomeMethod {}
@end

, "SomeClass" "-notAwesomeMethod". ... , notAwesomeMethod , , , . .

, .h.

0

Source: https://habr.com/ru/post/1740531/


All Articles