Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

satans_banjo

macrumors regular
Original poster
Sep 12, 2005
218
0
SE London
i've followed the cocoa currency converter tutorial from the apple web site and i've managed to build it fine, but when i run it i get strange results for my currency conversions. i was wondering if you would be able to recognise what the problem is

here is the code i put into the files:

ConverterController.m
Code:
#import "ConverterController.h"
#import "Converter.h"

@implementation ConverterController
- (IBAction)convert:(id)sender
{
	float rate, currency, amount;
	currency = [dollarField floatValue];
	amount = [converter convertCurrency:currency atRate:rate];
	[amountField setFloatValue:amount];
	[rateField selectText:self];
}

@end

ConverterController.h:
Code:
/* ConverterController */

#import <Cocoa/Cocoa.h>

@interface ConverterController : NSObject
{
    IBOutlet NSTextField *amountField;
    IBOutlet id converter;
    IBOutlet NSTextField *dollarField;
    IBOutlet NSTextField *rateField;
}
- (IBAction)convert:(id)sender;
@end

Converter.m:
Code:
#import "Converter.h"

@implementation Converter
-	(float)convertCurrency:(float)currency atRate:(float)rate	{
		return currency * rate;
}
@end

Converter.h:
Code:
/* Converter */

#import <Cocoa/Cocoa.h>

@interface Converter : NSObject {}
- (float)convertCurrency:(float)currency atRate:(float)rate;
@end

i didn't get any build errors or warnings for any of these. i've also taken some screenshots of what i did in interface builder to see if there was a problem there
 

Attachments

  • Error.jpg
    Error.jpg
    177.8 KB · Views: 126
  • ConvertButton.jpg
    ConvertButton.jpg
    186.1 KB · Views: 109
  • ConverterController.jpg
    ConverterController.jpg
    168 KB · Views: 107
  • NSWindow.jpg
    NSWindow.jpg
    164.5 KB · Views: 119

caveman_uk

Guest
Feb 17, 2003
2,390
1
Hitchin, Herts, UK
Your ConverterController.h file is the same as the .m file. Is that what you meant to post? If so, it's wrong. The .h is for variable and method declarations - not code.

BTW, you've got an icon on your dock that looks like a dog with chopsticks. What app is that?
 

satans_banjo

macrumors regular
Original poster
Sep 12, 2005
218
0
SE London
it's doggibox - a drum sequencing app. it's a good app and it's shareware so there's no obligation to buy anything

thanks for pointing that out. i must have been not paying attention and just copied the same code into both files

EDIT: actually hang on, i copied the .m twice. i've edited it now
 

caveman_uk

Guest
Feb 17, 2003
2,390
1
Hitchin, Herts, UK
The reason it's not working is that you're missing a line in ConverterController.m that says

rate=[rateField floatValue];

otherwise rate just has any old random value in it.

BTW, you should really pay for shareware you use (says the shareware developer ;) )
 

satans_banjo

macrumors regular
Original poster
Sep 12, 2005
218
0
SE London
wahey! thanks!

oh yeah - the shareware price is to unlock new features, which i don't need right now. of course it's a great program so if i ever get around to making a profit on my home recordings it'll be th first thing i invest in
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.