Skip to content

Commit d433d0c

Browse files
committed
my obj-c dabblings
1 parent d1901ab commit d433d0c

File tree

15 files changed

+5648
-0
lines changed

15 files changed

+5648
-0
lines changed

‎.gitignore‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.DS_Store
2+
build/*

‎APPL.icns‎

262 KB
Binary file not shown.

‎Converter.h‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//
2+
// Converter.h
3+
// Currency Converter
4+
//
5+
// Created by Chris Wanstrath on 4/22/08.
6+
// Copyright 2008 __MyCompanyName__. All rights reserved.
7+
//
8+
9+
#import <Cocoa/Cocoa.h>
10+
11+
12+
@interface Converter : NSObject {
13+
float sourceCurrencyAmount, rate;
14+
NSString* symbol;
15+
}
16+
17+
@property(readwrite) float sourceCurrencyAmount, rate;
18+
@property(readwrite, retain) NSString* symbol;
19+
- (float)convertCurrency;
20+
- (void)setCurrency:(NSString*)currency;
21+
@end

‎Converter.m‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//
2+
// Converter.m
3+
// Currency Converter
4+
//
5+
// Created by Chris Wanstrath on 4/22/08.
6+
// Copyright 2008 __MyCompanyName__. All rights reserved.
7+
//
8+
9+
#import "Converter.h"
10+
11+
@implementation Converter
12+
@synthesize sourceCurrencyAmount, rate, symbol;
13+
14+
- (float)convertCurrency {
15+
return self.sourceCurrencyAmount / self.rate;
16+
}
17+
18+
- (void)setCurrency:(NSString*)currency {
19+
if ([currency isEqualToString:@"Euros"]) {
20+
self.symbol = @"";
21+
self.rate = 1.5884;
22+
} else if ([currency isEqualToString:@"Pesos"]) {
23+
self.symbol = @"$";
24+
self.rate = 0.095578;
25+
} else if ([currency isEqualToString:@"Yen"]) {
26+
self.symbol = @"¥";
27+
self.rate = 0.009674;
28+
}
29+
}
30+
@end

‎ConverterController.h‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//
2+
// ConverterController.h
3+
// Currency Converter
4+
//
5+
// Created by Chris Wanstrath on 4/22/08.
6+
// Copyright 2008 __MyCompanyName__. All rights reserved.
7+
//
8+
9+
#import <Cocoa/Cocoa.h>
10+
#import "Converter.h"
11+
12+
@interface ConverterController : NSObject {
13+
IBOutlet NSTextField *amountField;
14+
15+
IBOutlet NSTextField *dollarField;
16+
17+
IBOutlet NSPopUpButton *ratePopUp;
18+
19+
IBOutlet NSButton *convertButton;
20+
21+
Converter *converter;
22+
}
23+
24+
-(id)init;
25+
26+
-(void)convert;
27+
-(IBAction)convert:(id)sender;
28+
29+
-(IBAction)switchObject:(id)sender;
30+
31+
- (void)controlTextDidChange:(NSNotification *)aNotification;
32+
33+
@end

‎ConverterController.m‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//
2+
// ConverterController.m
3+
// Currency Converter
4+
//
5+
// Created by Chris Wanstrath on 4/22/08.
6+
// Copyright 2008 __MyCompanyName__. All rights reserved.
7+
//
8+
9+
#import "ConverterController.h"
10+
11+
@implementation ConverterController
12+
-(id)init {
13+
converter = [[Converter alloc] init];
14+
return [super init];
15+
}
16+
17+
-(void)convert {
18+
[self convert:nil];
19+
}
20+
21+
-(IBAction)convert:(id)sender {
22+
converter.sourceCurrencyAmount = [dollarField floatValue];
23+
24+
NSString* amount = converter.symbol;
25+
amount = [amount stringByAppendingFormat:@"%.02f", [converter convertCurrency]];
26+
27+
[amountField setStringValue:amount];
28+
}
29+
30+
-(IBAction)switchObject:(id)sender {
31+
[converter setCurrency:[sender titleOfSelectedItem]];
32+
if ([dollarField floatValue] > 0) [self convert];
33+
}
34+
35+
36+
- (void)controlTextDidChange:(NSNotification *)aNotification {
37+
if ([dollarField floatValue] <= 0) [amountField setIntValue:0];
38+
else if ([dollarField floatValue] > 0 && converter.rate > 0) [self convert];
39+
}
40+
@end
51.1 KB
Binary file not shown.

0 commit comments

Comments
 (0)