iOS sending parameter to selector using NSTimers

Is there a way to send a parameter to the selector via a NSTimer ?

myTimer =[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(removeTheNote:) userInfo:nil repeats:NO];

      - (void)removeTheNote:(NSString*)note
    {
        NSLog(@"Note %@ ----------- REMOVED!",note);
    }

I know that using :

myTimer =[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(removeTheNote:myNote) userInfo:nil repeats:NO];

doesn't work, so I am asking, is there a way to do this?

Answers


You can use the userInfo parameter for that:

myTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(removeTheNote:) userInfo:myNote repeats:NO];

But you will have to modify removeTheNote as follows:

- (void)removeTheNote:(NSTimer *)timer
{
    NSString *note = timer.userInfo;
    NSLog(@"%@", note);
} 

Need Your Help

Pass the typed text to the remote request with typeahead bloodhound

typeahead.js twitter-typeahead bloodhound

I've seem some topics about the same issue, but all of them seem to be using the replace option.

Getting md5sum of a file through Crypto.js

javascript linux md5 fileapi cryptojs

I am trying to get the md5sum of a tar file to produce the same value when using the md5sum linux command and CryptoJS's MD5 method.