如何在类的@implementation中创建一个方法而不在@interface中定义它?
例如,我有一个构造函数,它进行一些初始化,然后从文件中读取数据.我想将文件读取代码分解为一个单独的方法,然后我在构造函数中调用它.我不想在标头中定义此方法,因为它仅对此@implementation上下文是私有的.
这可能吗?
这是我的例子.我有一个小程序,它从文件中读取了Todo任务列表.
这是@interface:
@interface TDTaskList : NSObject {
NSString* name; // The name of this list.
NSMutableArray* tasks; // The set of tasks in this list.
}
-(id)initListOfName:(NSString*)aName;
-(NSArray*)loadListWithName:(NSString*)aName;
@end
Run Code Online (Sandbox Code Playgroud)
这是@implementation的一部分:
-(id)initListOfName:(NSString*)aName {
if (self = [super init]) {
name = aName;
NSArray* aTasks = [self loadListWithName:aName];
tasks = [NSMutableArray arrayWithArray:aTasks];
}
return self;
}
-(NSArray*)loadListWithName:(NSString*)aName {
// TODO This is a STUB till i figure out how to read/write from a file ...
TDTask* task1 = [[TDTask …Run Code Online (Sandbox Code Playgroud)