-
Notifications
You must be signed in to change notification settings - Fork 4
/
ConverterController.m
40 lines (31 loc) · 1003 Bytes
/
ConverterController.m
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