Its essence is the expansion of a class, there are two ways to extend the class:
(1) by inheritance (often used)
(2) by category
A known class name
Its header file Name.h
#import <Foundation/Foundation.h>
@interface Name:nsobject
@property (strong,nonatomic) nsstring* nameStr;
-(Name *) init: (nsstring*) namestring;
-(void) namevalue;
@end
its implementation file NAME.M
#import "Name.h"
@implementation Name
-(Name *) init: (nsstring*) namestring
{
Name * name = [name new];
Name.namestr = namestring;
return name;
}
-(void) namevalue
{
NSLog (@ "----%@--", SELF.NAMESTR);
}
@end
Create a new header file name+change.h is used to declare the method that it wants to expand
Source:
#import "Name.h"
@interface Name (change)
-(void) Addnameid: (NSString *) str;
@end
Create a new implementation file NAME+CHANGE.M a way to implement your own expansion.
#import <Foundation/Foundation.h>
#import "Name+change.h"
#import "Name.h"
@implementation Name (change)
-(void) Addnameid: (NSString *) str
{
NSLog (@ "---%@--%@--", self.namestr,str);
}
@end
Its test file Selection command line
Main.m
#import <Foundation/Foundation.h>
#import "Name+change.h"
int main (int argc, const char * argv[]) {
@autoreleasepool {
Name * name1 = [[Name alloc] init:@ "Wangfei"];
[Name1 Namevalue];
[Name1 addnameid:@ "898989"];
}
return 0;
}
Its test results:
2015-07-11 16:34:53.051 category[1462:60100]----wangfei--
2015-07-11 16:34:53.053 category[1462:60100]---wangfei--898989--
Program ended with exit code:0
Implementation code about the IOS classification (category)