EDIT: It works but it takes amazingly long to complete.
Is this normal, or is there a way to optimize it?
Thanks
I am using DDUnitConverter in my project to convert currencies.
Everything works perfectly fine on the iOS Simulator but hangs when I try to convert the currencies on my iOS Device (iPhone 4 iOSv5.1). I looked around to find a fix to this issue but could not find anything. Here is the code that I use to exchange the currencies. The code within the DDUnitConverter is available here: https://github.com/davedelong/DDUnitConverter/downloads
if ([Number.text isEqualToString:@""] || [picklable.text isEqualToString:@"no selection"] || [picklable2.text isEqualToString:@"no selection"]) {
return;
}
if ([Number.text isEqualToString:@"0"]) {
Result.text = @"0";
return;
}
int fromType;
int toType;
fromType = [list indexOfObject:picklable.text];
toType = [list indexOfObject:picklable2.text];
NSNumberFormatter * f = [[NSNumberFormatter alloc] init];
[f setNumberStyle:NSNumberFormatterDecimalStyle];
NSNumber * from = [[f numberFromString:Number.text] retain];
[f release];
NSNumber *to = [[[DDUnitConverter currencyUnitConverter] convertNumber:from fromUnit:fromType toUnit:toType] retain];
float toto = [to floatValue];
Result.text = [NSString stringWithFormat:@"%.4f %@", toto, picklable2.text];
if ((toto == 0 || toto == [Number.text floatValue]) && picklable.text != picklable2.text ) {
Result.text = @"No Internet Connection or Previous Data";
}
[from release];
[to release];
[Result flashScrollIndicators];
Hopefully someone can help me out,
Thanks
Your code seems OK to me, but you are using DDUnitConverter. I’ve never used it, but I suppose it needs internet connection to load data from the internet. If the server take long time to answer, your app could hang on connection.
You can try to connect to the server asynchronously using
dispatch_async, this lets your app download data in background.