Search code examples
iosobjective-ciphoneobjective-c-runtime

passing float variable as parameter


I am trying to write a method with float parameter and call it using performSelector` but I am getting error in doing this. Following is my code:

[sender performSelector:selector withObject:progress/total];

Here progress and total both are float variable.

I am trying to call following method in different class:

-(void) updateProgress:(float)fl {
    
}

Solution

  • You need to pass a real object, not one of the basic types like int or float.

    Wrap it into an NSNumber object:

    [sender performSelector:selector withObject:[NSNumber numberWithFloat:progress/total]];
    
    -(void) updateProgress:(NSNumber *)aProgress {
       float fProgress = [aProgress floatValue];
    }