//
// main.m
// category
//
// Created by mj on 13-4-4.
// Copyright (c) 2013ๅนด itcast. All rights reserved.
//
#import
#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 test];
[stu test2];
[stu test3];
NSLog(@"%@", [NSString json]);
}
return 0;
}
//
// Student.h
// category
//
// Created by mj on 13-4-4.
// Copyright (c) 2013ๅนด itcast. All rights reserved.
//
#import
@interface Student : NSObject
- (void)test;
@end
// 在Student.h声明一个Student的分类,不一定要在别的文件中声明分类。
// 用括号"()"来表示分类,括号中的Addition表示分类名
@interface Student(Addition)
- (void)test3;
@end
//
// Student.m
// category
//
// Created by mj on 13-4-4.
// Copyright (c) 2013年 itcast. All rights reserved.
//
#import "Student.h"
@implementation Student
- (void)test {
NSLog(@"调用了test方法");
}
@end
// 在Student.m文件中实现Student的这个分类
@implementation Student(Addition)
- (void)test3 {
NSLog(@"调用了test3方法");
}
@end
//
// Student+Test.h
// category
//
// Created by mj on 13-4-4.
// Copyright (c) 2013年 itcast. All rights reserved.
//
#import "Student.h"
// ()代表着是一个分类
// ()中的Test代表着分类的名称
@interface Student (Test)
// 分类只能扩展方法,不能增加成员变量
- (void)test2;
@end
//
// Student+Test.m
// category
//
// Created by mj on 13-4-4.
// Copyright (c) 2013年 itcast. All rights reserved.
//
#import "Student+Test.h"
@implementation Student (Test)
- (void)test2 {
NSLog(@"调用了test2方法");
}
@end
//
// main.m
// category
//
// Created