Take the 2008 Git User's Survey and help out! [ hide ]

public
Clone URL: git://github.com/defunkt/currency_converter.git
Search Repo:
currency_converter / ConverterController.m
100644 40 lines (31 sloc) 1.003 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//
// ConverterController.m
// Currency Converter
//
// Created by Chris Wanstrath on 4/22/08.
// Copyright 2008 __MyCompanyName__. All rights reserved.
//
 
#import "ConverterController.h"
 
@implementation ConverterController
-(id)init {
    converter = [[Converter alloc] init];
    return [super init];
}
 
-(void)convert {
    [self convert:nil];
}
 
-(IBAction)convert:(id)sender {
    converter.sourceCurrencyAmount = [dollarField floatValue];
    
    NSString* amount = converter.symbol;
    amount = [amount stringByAppendingFormat:@"%.02f", [converter convertCurrency]];
    
    [amountField setStringValue:amount];
}
 
-(IBAction)switchObject:(id)sender {
    [converter setCurrency:[sender titleOfSelectedItem]];
    if ([dollarField floatValue] > 0) [self convert];
}
 
 
- (void)controlTextDidChange:(NSNotification *)aNotification {
    if ([dollarField floatValue] <= 0) [amountField setIntValue:0];
    else if ([dollarField floatValue] > 0 && converter.rate > 0) [self convert];
}
@end