

#import "MainView.h"
#import "ArchiversAppDelegate.h"
#import "Person.h"


@implementation MainView

@synthesize firstNameField, lastNameField;


- (id)initWithFrame:(CGRect)frame {
	if (self = [super initWithFrame:frame]) {
		// Initialization code
	}
	return self;
}


- (void)drawRect:(CGRect)rect {
	// Drawing code
}

- (IBAction) addNewPersonToArray:(id)sender {
	NSLog(@"adding new person");
	ArchiversAppDelegate *mainDelegate = (ArchiversAppDelegate *)[[UIApplication sharedApplication] delegate];
	Person *newPerson = [[Person alloc] init]; 
	
	[newPerson setFirstName:firstNameField.text];   NSLog(@"%@", newPerson.firstName);
	[newPerson setLastName:lastNameField.text];     NSLog(@"%@", newPerson.lastName);
	[mainDelegate.personArray insertObject:newPerson atIndex:[mainDelegate.personArray count]];
	[newPerson release];
}

- (IBAction) logArrayContents:(id)sender {
	ArchiversAppDelegate *mainDelegate = (ArchiversAppDelegate *)[[UIApplication sharedApplication] delegate];
	
	for(int i = 0; i < [mainDelegate.personArray count]; i++) {
		NSLog(@"%i. %@ %@", i, [[mainDelegate.personArray objectAtIndex:i] firstName], [[mainDelegate.personArray objectAtIndex:i] lastName]);
	}
}

- (void)dealloc {
	[firstNameField release];
	[lastNameField release];
	[super dealloc];
}


@end
