How can I create a method in the @implementation of a class without defining it in the @interface?
For example, I have a constructor that does some initialisation and then reads data from a file. I want to factor out the file-reading code into a separate method that I then call from within the constructor. I don't want to define this method in the header because it's private only to this @implementation context.
Is this possible?
Here's my example. I have a little program that read's a Todo task-list from a file.
Here is the @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
And here is part of the @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 alloc] initWithLabel:@"Get the Milk."];
TDTask* task2 = [[TDTask alloc] initWithLabel:@"Do some homework."];
return [NSArray arrayWithObjects:task1, task2, nil];
}
What I want to do is to not have to define the following in the interface:
-(NSArray*)loadListWithName:(NSString*)aName;