I've been trying to pull the value "tempF" from /var/mobile/Library/Preferences/com.skylerk99.snappref.plist to return for the float value.
-(float) temperatureDegFahrenheit {
NSDictionary *pref = [[NSDictionary alloc]initWithContentsOfFile:@"/var/mobile/Library/Preferences/com.sky.snap.plist"];
NSString *tempF;
if( [[pref objectForKey:@"showF"] boolValue] ) {
return tempF;
}
else {
return %orig;
}
}
but I keep getting the error
cannot initialize return object of type 'float' with an lvalue of type 'NSString *'
return tempF;
What is the best way to accomplish this, because I obviously don't know?
Update:
Based on the discussion below, let's assume the temperature is entered through a UITextField
called temperatureTextField. You can get the float value of the input temperature like this:
[[temperatureTextField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] floatValue];
The function expects you to return float
, but tempF is a NSString *
.
To parse float
value from a NSString
, try this (by the way, I assume that you did not show all your code, otherwise your tempF was never assigned):
[tempF floatValue];