Passing of data using Timer

suggest change

If you you want to pass some data with the timer trigger you can do it with the userInfoparameter.

Here is the simple approach that gives brief idea about how you can pass the data to triggered method from the Timer.

[Swift 3]

Timer.scheduledTimer(timeInterval: 1.0, target: self, selector:#selector(iGotCall(sender:)), userInfo: ["Name": "i am iOS guy"], repeats:true)

[Objective - C]

NSTimer* timer = [NSTimer scheduledTimerWithTimeInterval:1.0
                                                      target:self
                                                    selector:@selector(iGotCall:)
                                                    userInfo:@"i am iOS guy" repeats:YES];

The above line of code passing ["Name": "i am iOS guy"] into the userInfo. So now when the iGotCall get call you can get the passed value as below code snippet.

[Swift 3]

func iGotCall(sender: Timer) {
        print((sender.userInfo)!)
    }

[Objective - C]

- (void)iGotCall:(NSTimer*)theTimer {
    NSLog (@"%@", (NSString*)[theTimer userInfo]);
}

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


NSTimer:
* Passing of data using Timer

Table Of Contents
12 UIView
15 UIColor
26 UIImage
28 CALayer
30 NSDate
40 iBeacon
49 NSTimer
79 NSURL
87 AWS SDK
96 NSData
101 Segues
104 EventKit
105 NSBundle
106 SiriKit
111 StoreKit
117 3D Touch
119 Keychain
122 Block
141 AirDrop
144 UISlider
145 Carthage
146 HealthKit
151 plist
157 MVVM
164 UIPhoenix
166 Simulator
168 NSArray
169 OpenGL
175 Core Data
179 MyLayout
180 UIFont
189 Security
200 Codable