When creating a timer, you can set the userInfo
parameter to include information that you want to pass to the function you call with the timer.
By taking a timer as a parameter in said function, you can access the userInfo
property.
NSDictionary *dictionary = @{
@"Message" : @"Hello, world!"
}; //this dictionary contains a message
[NSTimer scheduledTimerWithTimeInterval:5.0
target:self
selector:@selector(doSomething)
userInfo:dictionary
repeats:NO]; //the timer contains the dictionary and later calls the function
...
- (void) doSomething:(NSTimer*)timer{
//the function retrieves the message from the timer
NSLog("%@", timer.userInfo["Message"]);
}