Objective-C在单独文件中部分实现类

Ara*_*and 6 iphone cocoa class-design objective-c

我正在使用核心数据,并从我的数据模型生成类.

我在这些类中实现自定义方法,但是当我重新生成i生成顶部时,我最终复制并粘贴一点.我想要做的是拆分我的实现文件('.m'),这样我就可以有一个包含多个'.m'文件的头文件.然后我可以将我的自定义方法保存在一个中,而不必担心在重新生成时擦除它们.我在.NET中使用了这个技术,并使用了partial关键字.Objective-C中是否有类似的东西

Til*_*eis 16

在Objective-C中,您有类别(和扩展名).

如果您的CoreData类已命名,Person您的实现可以进入该类别,Implementation但请注意您必须在类的主界面中声明所有ivars.

// Person+Implementation.h
#import "Person.h"

@interface Person (Implementation)
- (void)myMethod;
@end


// Person+Implementation.m
#import "Person+Implementation.h"

@implementation Person (Implementation)
- (void)myMethod {
    NSLog(@"hi there");
}
@end
Run Code Online (Sandbox Code Playgroud)


Pet*_*sey 2

您可能还想看看mogenerator,它采用不同的方法来为实体生成类。