FloatValue for CGFloat

I have an NSSlider that is trying to convert a regular float to CGFloat. The code I'm using is:

CGFloat testing = [mainSlider floatValue];

However, this simply makes the test variable "0.00" when trying to register it.

NSLog(@"%f", testing);

Does anyone have any idea why this will happen? Thanks for any help.

+5
source share
1 answer
  • make sure mainSlider is not nil
  • try this just in case (I donโ€™t remember whether CGFloat is double or not) :

    NSLog (@ "% f", (double) testing);

  • Make sure the variable is not obscured as follows:

    CGFloat testing = 0.0;
    if(YES){
        CGFloat testing = [mainSlider floatValue];
        //should be: testing = [mainSlider floatValue];
    }
    NSLog(@"testing = %f", testing); //this will print "testing = 0.000000"
    
+10
source

All Articles