Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

floatValue for CGFloat

Tags:

cocoa

slider

I have a NSSlider that is attempting to convert a regular float into a CGFloat. The code that I am using:

CGFloat testing = [mainSlider floatValue];

However this simply makes the testing variable "0.00" when I attempt to log it.

NSLog(@"%f", testing);

Does anyone have any ideas as to why this would happen? Thanks for any help.

like image 398
PF1 Avatar asked Aug 04 '09 03:08

PF1


1 Answers

  1. check that mainSlider isn't nil
  2. try this just in case (can't remember if CGFloat is a double or not):

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

  3. Check that the variable isn't being shadowed like this:

    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"
    
like image 62
Tom Dalling Avatar answered Sep 22 '22 11:09

Tom Dalling