I went through one of the Apple tutorials (second iOS app). Basically, you have a primary data class and a data controller class. The controller class manages the primary data objects, creating an array that holds them.
Suddenly this pops up:
"... But the task of" creating the main collection "is a task that only the data controller object needs to know about. Since this method does not need to be exposed to other objects, you do not need to declare it in the header file."
And it turns out that the initialization of the "main collection" appears in the .m file as an extension of the class instead of the header file. Why do we want to do this? What is wrong with declaring the initialization method inside the header file directly?
Data controller header file:
#import <Foundation/Foundation.h>
@class BirdSighting;
@interface BirdsSightingDataController : NSObject
@property (nonatomic, copy) NSMutableArray *masterBirdSightingList;
- (NSUInteger)countOfList;
- (BirdSighting *)objectInListAtIndex:(NSUInteger)theIndex;
- (void)addBirdSightingWithName:(NSString *)inputBirdName location:(NSString *)inputLocation;
@end
this is the corresponding .m file:
#import "BirdsSightingDataController.h"
#import "BirdSighting.h"
@interface BirdsSightingDataController ()
- (void)initializeDefaultDataList;
@end
@implementation BirdsSightingDataController
...
source
share