question concerning NSLog and the output in console

Discussion in 'iOS Programming' started by ulquiorra, Sep 11, 2009.

  1. ulquiorra macrumors member

    Joined:
    Jun 17, 2009
    #1
    I have question concerning a function I created.
    I would like to show the timeinterval in my console output.


    Code:
        -(void)MyTimeInterval:(id)sender
        {
        	NSDate *then = [NSDate date];
        	 
        	NSDate *now = [NSDate date];
        	
        	NSTimeInterval interval = [now timeIntervalSinceDate:then];
        	
        	NSLog(@"let me see the timeinterval between now and then %d", interval);
        }
    
    
    Does anyone have an idea what I should use to see the interval in the console output.
    It's not %d... I don't think I'm doing something wrong here in my function ( could be wrong of course ) , so I'm guessing it must be %d.
     
  2. ulquiorra thread starter macrumors member

    Joined:
    Jun 17, 2009
    #2
    I'm going to answer my own question here and not delete it maybe it can be usefull to someone else

    it's %f ;)
     
  3. Darkroom Guest

    Darkroom

    Joined:
    Dec 15, 2006
    Location:
    Montréal, Canada
    #3
    NSTimeInterval is not an integer, it's an object.

    Code:
    NSDate *dateObject = [NSDate date];
    NSLog(@"[B]%@[/B]", dateObject);
    
    int dateInteger = 5;
    NSLog(@"%i", dateInteger);
    
    float dateFloat = 4.84682;
    NSLog(@"%.2f", dateFloat);
    
     
  4. HerQ macrumors newbie

    Joined:
    Jun 11, 2008
    Location:
    The Netherlands
    #4
    NSTimeInterval is _not_ an object, it simply is a typedef of double.
     
  5. Darkroom Guest

    Darkroom

    Joined:
    Dec 15, 2006
    Location:
    Montréal, Canada
    #5
    woops, meant to write NSDate in line with my example... :eek:

    [edit] and that still wouldn't have answered the OP's question, which leads me to believe it's time for the first morning coffee
     

Share This Page