I have no idea how to program in Objective C. I'm a Javascript guy. I'm trying to modify this Phonegap plugin and I think I'm 99% there.
In the full code below, if i set self.progressHUD.progess = .5;
it works great!. But if I set that to the variable progress
it doesn't compile at all. And Phonegap doesn't give me any compilation errors to go off of. I don't understand why I can't set this property to a variable.
(void)setValue:(CDVInvokedUrlCommand*)command
{
NSNumber* progress = [command argumentAtIndex:0];
if (!self.progressHUD) {
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
return;
}
self.progressHUD.progress = progress;
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:@""];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}
Thanks!
The progress
property of MBProgressHUD is of scalar type float
, but your progress variable is an object of type NSNumber. You need to get the raw float value from your NSNumber object; you can do this with the floatValue
property:
self.progressHUD.progress = progress.floatValue;
(This is assuming that the object returned by [command argumentAtIndex:0]
is always an NSNumber; there is no runtime guarantee of this, so it depends on the code that creates the command object to be correct.)
You will often see integral values (int, BOOL, float, and their typedef counterparts NSInteger, CGFloat, etc.) boxed as NSNumber or related objects in Objective-C. This is because there are many cases where a data structure (such as NSArray or NSDictionary) only works with pointers to NSObjects. Objective-C provides various ways to box and unbox values.