Questions tagged [nstimer]

An Objective C class for creating timer objects.

In Objective C (), you use the NSTimer class to create timer objects or, more simply, timers. A timer waits until a certain time interval has elapsed and then fires, sending a specified message to a target object. For example, you could create an NSTimer object that sends a message to a window, telling it to update itself after a certain time interval.

Timers work in conjunction with run loops. To use a timer effectively, you should be aware of how run loops operate—see NSRunLoop and Threading Programming Guide. Note in particular that run loops retain their timers, so you can release a timer after you have added it to a run loop.

A timer is not a real-time mechanism; it fires only when one of the run loop modes to which the timer has been added is running and able to check if the timer’s firing time has passed. Because of the various input sources a typical run loop manages, the effective resolution of the time interval for a timer is limited to on the order of 50-100 milliseconds. If a timer’s firing time occurs during a long callout or while the run loop is in a mode that is not monitoring the timer, the timer does not fire until the next time the run loop checks the timer. Therefore, the actual time at which the timer fires potentially can be a significant period of time after the scheduled firing time.

NSTimer is “toll-free bridged” with its Core Foundation () counterpart, CFRunLoopTimerRef. See “Toll-Free Bridging” for more information on toll-free bridging.

Additional examples for the NSTimer object can be found here.

2624 questions
0
votes
0 answers

Instantiating and keeping track of multiple timers in SWIFT 3

So my problem looks like this: I am working on an app to keep track of some data-loggers. I am an electronic engineer so I new to swift. In a tableview I list all connected devices, and when I tap in one cell, it takes me to another tableview with…
Danf
  • 1,409
  • 2
  • 21
  • 39
0
votes
2 answers

NSTimer in NSOperation subclass

Dear community. I try to setup NSTimer: @interface GetExternalInfo : NSOperation { NSTimer *keepAliveTimerMain; @property (nonatomic,retain) NSTimer *keepAliveTimerMain; .m: @synthesize keepAliveTimerMain -(void) main; { self.keepAliveTimerMain…
Alex
  • 393
  • 6
  • 21
0
votes
2 answers

Multiple timers at once ios

I am making an app where the user can have multiple timers going at once and see them in a list view. I am aware that there are 2 main options for working out time: Subtract the date started from current date (current date-start date) OR Use an…
D-A UK
  • 1,084
  • 2
  • 11
  • 24
0
votes
1 answer

NSImageView update delayed when set from an NSTimer

I'm working on a project in Swift that requires strict control of image display and removal timings in certain sections. I'm finding that when I set the image property of an NSImageView from inside a block that's fired by a Timer, the actual display…
0
votes
3 answers

Timer not working properly in UITableView cell in iOS

I'm creating a timer in tableview cell's class and updating a label each second using the timer. But the label is getting updating multiple times each second for some cells while it is being updated at a different rate for other cells. I think the…
Romit Kumar
  • 2,442
  • 6
  • 21
  • 34
0
votes
0 answers

Trying to get a timer to work with UICollectionViewCell

My goal is to get my timer working with each UITableViewCell. Currently, I'm able to use a timer just fine with a normal ViewController when I set up the @objc method, and selector of that method. I'm trying to figure out what is wrong with my…
bradford gray
  • 537
  • 2
  • 5
  • 18
0
votes
2 answers

How do I get time-server live time via jQuery

In windows there is an option to correct the time via time-server(from time.windows.com). Is there an option to get that time server's time to a webpage with live update (I'm a beginner) using js or jQuery. This is not the local computer or…
user8149677
0
votes
1 answer

How to animate background?

i try to animate background in my app. I use an image view with an image and on view load I started a timer that scroll image. It's all ok, i decrement x and the image seems to be animated. But, when the image end (in my case 800px) i reset x to 0…
elp
  • 8,021
  • 7
  • 61
  • 120
0
votes
1 answer

i am tying to work timer through app

I am working on an app that requires timing. The timer activates in one View Controller and it needs to continue until the last View Controller or resign the app. For example, I have2 View Controllers and the timer need to start in second View…
Suraj Sharma
  • 9
  • 1
  • 5
0
votes
0 answers

How to achieve accuracy of timer upto nanosecond or millisecond in iOS?

We are developing a game to find a mismatch, the one who finds in the lowest time wins the game. Currently, we have used DispatchSourceTimer to perform the tracking of timing in the unit of seconds SS.XXXX with 4 decimal point in consideration, so…
Prakash Donga
  • 558
  • 5
  • 10
0
votes
4 answers

NSTimer stops the first time I tell it to, then refuses to stop

I have declared an NSTimer in my UIViewController header as such: NSTimer *mainTimer; And I start it up in the viewWillAppear method in the implementation, so: mainTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self…
Steve
  • 6,332
  • 11
  • 41
  • 53
0
votes
1 answer

WatchOS: how can i play sound when watch going on lock screen?

I am developing apple watch application. my application working like every second it's notify sound and vibrate on my watch app. Otherwise How can i stop watch from going to lock screen after 15 second? My code is as follows. - (void)willActivate…
BuLB JoBs
  • 841
  • 4
  • 20
0
votes
2 answers

Extracting Minute Form NSTimer Which Tics Every Second

timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(myMethod) userInfo:nil repeats:YES]; -(void)myMethod { //my every second requirment //my every minute requirment } My timer tics every second and its my…
0
votes
1 answer

NSTimer issue - Stop different timers using single functions

I am creating an application in that I need to use about 20 different Timers. But all the timers are going to be created at run time, by calling some function. All the timers might having different timer interval and all timer do have different…
V.V
  • 3,082
  • 7
  • 49
  • 83
0
votes
1 answer

NSTimer usage in Xamarin Ios

I am trying to build a App in IOS where I want UIButton to continuously change its background colour. I tried using Timer was not able to do it properly. I want the colour background to continuously change colour. If anyone has any idea please…
ASAS
  • 1
1 2 3
99
100