Created
June 1, 2009 07:36
-
-
Save akio0911/121291 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
@interface Account : NSObject | |
{ | |
float openingBalance; | |
NSString* name; | |
NSString* note; | |
NSMutableArray* transactions; | |
} | |
@property (nonatomic, assign) float openingBalance; | |
@property (nonatomic, retain) NSString* name; | |
@property (nonatomic, retain) NSString* note; | |
@property (nonatomic, retain) NSMutableArray* transactions; | |
@end | |
@implementation Account | |
@synthesize openingBalance; | |
@synthesize name; | |
@synthesize note; | |
@synthesize transactions; | |
- (id) init | |
{ | |
self = [super init]; | |
if (self != nil) { | |
openingBalance = 123.456f; | |
name = [[NSString alloc] initWithString:@"NAME"]; | |
note = [[NSString alloc] initWithString:@"NOTE"]; | |
transactions = [[NSMutableArray alloc] init]; | |
} | |
return self; | |
} | |
- (void)dealloc { | |
[name release]; | |
[note release]; | |
[transactions release]; | |
[super dealloc]; | |
} | |
@end | |
@interface Transaction : NSObject | |
{ | |
unsigned int referenceNumber; | |
double amount; | |
NSString* payee; | |
NSDate* date; | |
NSString* category; | |
BOOL reconciled; | |
} | |
@property (nonatomic, assign) unsigned int referenceNumber; | |
@property (nonatomic, assign) double amount; | |
@property (nonatomic, retain) NSString* payee; | |
@property (nonatomic, retain) NSDate* date; | |
@property (nonatomic, retain) NSString* category; | |
@property (nonatomic, assign) BOOL reconciled; | |
@end | |
@implementation Transaction | |
@synthesize referenceNumber; | |
@synthesize amount; | |
@synthesize payee; | |
@synthesize date; | |
@synthesize category; | |
@synthesize reconciled; | |
- (id) init | |
{ | |
self = [super init]; | |
if (self != nil) { | |
referenceNumber = 123; | |
amount = 123.456; | |
payee = [[NSString alloc] initWithString:@"PAYEE"]; | |
date = [[NSDate alloc] init]; | |
category = [[NSString alloc] initWithString:@"CATEGORY"]; | |
reconciled = NO; | |
} | |
return self; | |
} | |
- (void)dealloc { | |
[payee release]; | |
[date release]; | |
[category release]; | |
[super dealloc]; | |
} | |
@end | |
int main() { | |
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; | |
NSMutableArray* accountArray = [NSMutableArray array]; | |
Account* account1 = [[Account alloc] init]; | |
account1.openingBalance = 1000.0f; | |
[accountArray addObject:account1]; | |
[account1 release]; | |
NSLog(@"%@", [accountArray valueForKeyPath:@"@avg.openingBalance"]); | |
Account* account2 = [[Account alloc] init]; | |
account2.openingBalance = 2000.0f; | |
[accountArray addObject:account2]; | |
[account2 release]; | |
NSLog(@"%@", [accountArray valueForKeyPath:@"@avg.openingBalance"]); | |
Account* account3 = [[Account alloc] init]; | |
account3.openingBalance = 3000.0f; | |
[accountArray addObject:account3]; | |
[account3 release]; | |
NSLog(@"%@", [accountArray valueForKeyPath:@"@avg.openingBalance"]); | |
Account* savingsAccount = [[Account alloc] init]; | |
Transaction* transaction1 = [[Transaction alloc] init]; | |
[savingsAccount.transactions addObject:transaction1]; | |
[transaction1 release]; | |
Transaction* transaction2 = [[Transaction alloc] init]; | |
[savingsAccount.transactions addObject:transaction2]; | |
[transaction2 release]; | |
Transaction* transaction3 = [[Transaction alloc] init]; | |
[savingsAccount.transactions addObject:transaction3]; | |
[transaction3 release]; | |
NSLog(@"%@", [savingsAccount valueForKeyPath:@"transactions.@count"]); | |
[pool release]; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment