An extension of Objective-c: Extension

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.