標籤:blog os io 檔案 div log ef on
person+money.h 這是類目類
#import "Person.h"//這是擴充person類的介面類,獨立一個檔案@interface Person (Money)-(void) haveMoney;@end
person+money.m 這是類目類
#import "Person+Money.h"//這是擴充person類的實作類別,獨立一個檔案@implementation Person (Money)-(void) haveMoney{ NSLog(@"人人有錢");}@end
person.h
#import <Foundation/Foundation.h>//這是原始類@interface Person : NSObject@property(nonatomic,copy) NSString *name;@property(nonatomic,retain) NSNumber *age;-(void) originTest;@end//這是原始類的擴充類,直接定義與原始類同一檔案中@interface Person (Creat)+(id) personWithName:(NSString *) name;@end//這是原始類的擴充類,直接定義與原始類同一檔案中@interface Person (Test)-(void) test;@end
person.m
#import "Person.h"//這是person類的實作類別@implementation Person:NSObject-(id) init{ self=[super init]; NSLog(@"調用類自訂的init 方法"); return self;}+(id) personWithName:(NSString *) name{ Person *person=[[Person alloc] init]; person.name=name; return person;}//這是person類的實作類別,直接定義與原始類同一檔案中-(void) test{ NSLog(@"這是類目定義的方法");}-(void) originTest{ NSLog(@"這是原始類的方法");}-(void) haveMoney{ NSLog(@"人人有錢");}@end
person_family.h 這是延展的類
#import "Person.h"@interface Person ()-(void) haveFamily;@end
main.m
//類目擴充學習
Person *person=[Person personWithName:@"caictou"];
//這是原始類定義的方法
[person originTest];
//這是同一個檔案的擴充類定義的方法
[person test];
//這是獨立一個檔案的擴充類定義的方法
[person haveMoney];
//這是對立一個檔案的延展類定義的方法
[person haveFamily];