I’m trying to learn objective c. I have xcode 4 and am reading my way through a beginners book on how to make iphone applications.
I can code c sharp reasonable well but c is obviously lower level and involves a fair bit of memory management so I think that’s where i’m falling down here.
Anyway, I am trying to create a method of return type double. In c sharp I would write this as
public double test()
{
return 12;
}
I then want to be able to call my method from another method. Here’s part of what I’ve been working on so far.
- (double)test
{
return 1985;
}
- (IBAction)btnConvert_Click:(id)sender
{
double str = [double test];
NSString *hello = txtAmount.text;
double myDouble = [hello doubleValue] * exrate;
lblResult.text = [NSString stringWithFormat: @"%.2f", str];
}
It throws up an error where I try to establish the double method str “expected expression”. What I’d like to do is to pass in myDouble to test, then to do some calculations and then return the value.
How would I do that? Thanks.
Instead of
double str = [double test];you should writedouble str = [self test];since you are calling a method of your own class, not ondouble