#include "CheckBook.h" @implementation CheckBook -init { transactions = [NSMutableArray array]; return [super init]; } -loadFile:(NSString*)file { if(transactions) { NSLog(@"Erasing previous dictionary."); [transactions release]; } transactions = [NSMutableArray arrayWithContentsOfFile:file]; return self; } -saveFile:(NSString*)file { [transactions writeToFile:file atomically:YES]; return self; } -(double)balance { double balance; id objectEnum, object; objectEnum = [transactions objectEnumerator]; while(object = [objectEnum nextObject]) { if([[object objectForKey:@"Type"] isEqualToString:@"Debit"]) { balance -= [[object objectForKey:@"Amount"] doubleValue]; } else if([[object objectForKey:@"Type"] isEqualToString:@"Deposit"]) { balance += [[object objectForKey:@"Amount"] doubleValue]; } else { NSLog(@"Invalid type of transaction. Ignoring."); } } return balance; } -addEntry:(NSDictionary*)entry { [transactions addObject:entry]; return self; } -(void)dealloc { [transactions release]; // [super dealloc]; } @end