Thursday, October 1, 2009


This is the third post in a series, the first is here, and the second is here. In the first post I forgot something important---details of the header file and properties of the DataModel class.

If you go back to XCode, the files "DataModel.m" and "DataModel.h" should be present under Groups & Files. Where they went to depends on what was selected, if necessary drag them to the Classes tab.

Change the header file so that it looks like this:

#import <Cocoa/Cocoa.h>

@interface DataModel : NSObject {

NSMutableArray *dataArray;
NSMutableArray *temp;

@property (retain) NSMutableArray *dataArray;

- (void)loadFakeData;


With this @property directive, and a corresponding one in the .m file, we don't need to set accessor methods for our variable dataArray, and bindings will also work fine too.

In the implementation file, put in the code from the first post for the loadFakeData method. The top part of the file looks like this:

#import "DataModel.h"

@implementation DataModel

@synthesize dataArray;

- (id)init {
self = [super init];
if (self == nil) return nil;
NSLog(@"DataModel init %@",
[self description]);
[self loadFakeData];
return self;

We don't actually need an init method but it doesn't hurt. And it gives us a convenient place to call our other method, early enough so that when the application window appears it will look like this:

No comments: