Wednesday, 15 September 2010

iphone - NSTimer with anonymous function / block? -



iphone - NSTimer with anonymous function / block? -

i want able schedule 3 little events in future without having write function each. how can using nstimer? understand blocks facilitate anonymous functions can used within nstimer , if so, how?

[nstimer scheduledtimerwithtimeinterval:gameinterval target:self selector:@selector(/* want update label here */) userinfo:nil repeats:no];

you can create utilize of dispatch_after if want accomplish similar nstimer , block execution.

here sample code same:

int64_t delayinseconds = gameinterval; // game interval mentioned above dispatch_time_t poptime = dispatch_time(dispatch_time_now, delayinseconds * nsec_per_sec); dispatch_after(poptime, dispatch_get_main_queue(), ^(void){ // update label here. });

hope helps.

iphone objective-c nstimer

No comments:

Post a Comment