The following is a little bit of knowledge I learned during my learning process. Although it is superficial, I want to share it with you! I hope to give more advice.
First look at the code structure
Test
Main. m
SceneManager. h
SceneManager. m
SubSceneManager. h
SubSceneManager. m
------------------
The following is code implementation:
SceneManager. h
# Import <Foundation/Foundation. h>
@ Interface
SceneManager: NSObject
-(Void)
Go;
@ End
SceneManager. m
# Import
"SceneManager. h"
// Extend the Class-A method of hiding the wrap method (unforced)
@ Interface
SceneManager ()
+ (Void) wrap;
@ End
@ Implementation
SceneManager
-(Id) init
{
Self = [super init];
If (self ){
// Initialization code here.
}
Return self;
}
-(Void) go {
NSLog (@ "method of go ");
}
+ (Void) wrap {
NSLog (@ "method of wrap ");
}
@ End
SubSceneManager. h
# Import
"SceneManager. h"
@ Interface SubSceneManager:
SceneManager
@ End
SubSceneManager. m
# Import
"SubSceneManager. h"
@ Implementation SubSceneManager
-(Id) init
{
Self = [super init];
If (self ){
// Initialization code here.
}
Return self;
}
@ End
Main. m
# Import
<Foundation/Foundation. h>
# Import "scenemanager. H"
# Import
"Subscenemanager. H"
Int main (INT argc, const char * argv [])
{
NSAID utoreleasepool * Pool = [[NSAID utoreleasepool alloc] init];
Scenemanager * Sm = [[subscenemanager alloc] init];
[Sm go];
// This sentence should be commented out
/*
[Scenemanager wrap]; // a warning is reported: Class Method of "+ wrap" not found.
// Although it is a warning, it is normal to run, but it is not well written in self-standardization. Even if the compiler does not impose any restrictions, we have to limit ourselves.
// Otherwise, the extension method is meaningless.
*/
[Pool drain];
Return 0;
}
Certificate -----------------------------------------------------------------------------------------------------------------------------------------------------------
Although the call cannot be forcibly restricted, is it a good coding habit? I understand this.