Apple 称实现文件的附加目录(Continuation Category)为类的扩展(class extension)。
类的扩展像匿名目录(anonymous category)一样,我们可以在这一区域定义方法(method)、属性(property)和实例变量(instance variable)。当然,方法的具体实现需要在@implementation 代码块中编写。
我们可以这一区域为类定义额外的方法,而不是在@interface 中定义,如下是一段示例代码 — 其中蓝色标示的代码,就是我们所说的Continuation Category或Class Extension。
#import "ZoomImageViewController.h"
#define ZOOM_STEP 1.5
@interface ZoomImageViewController ()
@property (nonatomic, strong) UIImageView *imageView;
- (void)scrollViewDoubleTapped: (UITapGestureRecognizer *)recognizer;
- (void)scrollViewTwoFingerTapped:(UITapGestureRecognizer *)recognizer;
@end
@implementation ZoomImageViewController
@synthesize scrollView;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
}
- (void)scrollViewDoubleTapped: (UITapGestureRecognizer *)recognizer
{
// 编写具体实现代码
}
- (void)scrollViewTwoFingerTapped:(UITapGestureRecognizer *)recognizer
{
// 编写具体实现代码
}
@end