Timer functionality

Discussion in 'iOS Programming' started by Sergio10, May 23, 2009.

  1. Sergio10 macrumors regular

    Joined:
    Oct 3, 2007
    #1
    Hi,

    How to create timer? I need every second call some function(e.g. updateTimer)
    I developed:
    PHP:
        NSTimer timer = [NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(updateTimeruserInfo:nil repeats:YES];
    ...
    - (
    void)updateTimer:(id)sender
    {
        
    NSLog(@"my text\n");
    }
    But it crashes. What I'm doing wrong?

    Thanks.
     
  2. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
  3. macfanboy macrumors 6502a

    Joined:
    Jun 5, 2007
    #3
    why is there an f?
     
  4. firewood macrumors 604

    Joined:
    Jul 29, 2003
    Location:
    Silicon Valley
    #4
    It's C for "make this constant a single precision float", which is a complete and utter waste, since scheduledTimerWithTimeInterval takes a NSTimeInterval === a float double, so the parameter will get converted back to a float double before getting pushed on the stack for the function/method/message invocation anyway.
     
  5. BlackWolf macrumors regular

    Joined:
    Apr 9, 2009
    #5
    well, in the end it doesn't really matter. you are giving the timer the selector "updateTimer" but you have the method "updateTimer:" - so your method never gets called. but, your method is pretty wrong anyway, because the reference of NSTimer says:
    if you need to pass additional parameters you must use
    Code:
    scheduledTimerWithTimeInterval:invocation:repeats:
     

Share This Page