Category分類
1821 ワード
Student.h:
Student.m:
Student+Test.h
Student+Test.m:
NSString+JSON.h:
NSString+JSON.m:
main:
2013-08-02 15:47:57.364 Category[1322:303]Studentをテストする方法です
2013-08-02 15:47:57.366 Category[1322:303]分類方法Test 2です
2013-08-02 15:47:57.367 Category[1322:303]分類方法test 3です
2013-08-02 15:47:57.368 Category[1322:303] {'name':'dxw','id':10}
#import <Foundation/Foundation.h> @interface Student : NSObject @property(nonatomic) int no; -(void)TestStudent; @end
Student.m:
#import "Student.h" @implementation Student -(void)TestStudent{ NSLog(@" Student "); } @end
Student+Test.h
#import "Student.h" //() //Test @interface Student (Test) // : , -(void) Test2; @end @interface Student(Addtion) -(void) Test3; @end
Student+Test.m:
#import "Student+Test.h" @implementation Student (Test) -(void)Test2 { NSLog(@" Test2"); } @end @implementation Student(Addtion) -(void)Test3{ NSLog(@" test3"); } @end
NSString+JSON.h:
#import <Foundation/Foundation.h> @interface NSString (JSON) +(NSString *)json; @end
NSString+JSON.m:
#import "NSString+JSON.h" @implementation NSString (JSON) +(NSString *)json{ return @"{'name':'dxw','id':10}"; } @end
main:
#import <Foundation/Foundation.h> #import "Student.h" #import "Student+Test.h" #import "NSString+JSON.h" int main(int argc, const char * argv[]) { @autoreleasepool { Student *stu=[[[Student alloc] init] autorelease]; [stu TestStudent]; [stu Test2]; [stu Test3]; NSLog(@"%@",[NSString json]); } return 0; }
結果:2013-08-02 15:47:57.364 Category[1322:303]Studentをテストする方法です
2013-08-02 15:47:57.366 Category[1322:303]分類方法Test 2です
2013-08-02 15:47:57.367 Category[1322:303]分類方法test 3です
2013-08-02 15:47:57.368 Category[1322:303] {'name':'dxw','id':10}