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
1 answer

NSTimer gets disturbed while scrolling the UITableView in iphone

I have got a strange and rare problem here. I am using NSTimer event that play sound repeatedly at 100ms. I have UITableView in same class. When i scroll the tableview the timer gets disturbed. I mean the sound which was playing repeatedly becomes…
Ruchit Patel
  • 1,030
  • 1
  • 12
  • 24
0
votes
4 answers

How to move from one view controller to another Automatically with some time?

I am new to this development and i was working with splash screen but I don't know how to move from one view controller to another with some certain time... [self performSegueWithIdentifier:@"nameOfYourSegue" sender:self]; I don't know how to add…
user7853453
0
votes
1 answer

Using NSTimer to create a countdown

I have a int value representing a countdown to an event (view being displayed). Currently, i do this: - (void) buttonTapped:(id)sender { [self performSelector:@selector(displayView) afterDelay:countdownValue]; } What I would like to do is the…
joec
  • 3,533
  • 10
  • 60
  • 89
0
votes
1 answer

NSTimer is being triggered only one time after invalidating and reinitializing

I have the following function setPath() which is called whenever the user taps on a button: var loadSuccessfulTimer: Timer? = nil func setPath(index: Int) { self.loadSuccessfulTimer?.invalidate() self.loadSuccessfulTimer = nil …
MrGreen
  • 479
  • 4
  • 24
0
votes
0 answers

Need NSTimer running or Fire dynamic Local Notification at every certain time interval When Application is in background

As per my scenario i.e. needs to call api, then show local notification, again need to call api. so each time 3 procedure needs to followed, even if application is active or in background. I have tried to use NStimer for this but timer stops working…
0
votes
1 answer

How to set up a loop interval in Swift once a button is pressed?

I am trying to set up a looping interval timer for my buttons once they are pressed by the user. For instance, once the 'red' traffic signal is pressed, it will cycle through the remainder of the colours (in order) for a period of 5 seconds each.…
canyonlab
  • 11
  • 1
0
votes
1 answer

How to work with Timer, when app is in background

Am calling one function for every 4 seconds using Timer and if I tap on a button in the same viewController am navigating to google maps. After navigating to google maps that function is not getting called Here is by button action @IBAction func…
Bhanuteja
  • 41
  • 2
  • 6
0
votes
2 answers

How can I develop an alarm option in iPhone app?

I have two questions: How can I develop an Alarm option in iPhone application ? We should able to activate more than an Alarm in the app. We can use NSTimer, NSThread and etc... So which will give good performance ?
jfalexvijay
  • 3,681
  • 7
  • 42
  • 68
0
votes
2 answers

NStimer and for loop

I'm struggling with this. I saw some code where you can do this : - (void)startTimer { pauseTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(doActions) userInfo:nil repeats:YES]; } Then call it in…
Glen020
  • 187
  • 1
  • 12
0
votes
1 answer

Prevent NSTimer firing delays in background app

I'm working on a macOS app (let's call it the "display app") that displays a clock and other data, which is controlled by another app (the "control app") on the same machine via a TCP connection. I have noticed that when the display app is idle for…
fbitterlich
  • 882
  • 7
  • 24
0
votes
1 answer

Timer.scheduledTimer no available when using vapor?

I got this compile issue when compiling using vapor+Xcode: Below are some related info: $ vapor --version Vapor Toolbox: 3.1.7 Vapor Framework: 3.0.1 $ swift --version Apple Swift version 4.1 (swiftlang-902.0.48 clang-902.0.37.1) Target:…
Jay Zhao
  • 946
  • 10
  • 24
0
votes
0 answers

Timer object only calling selector once when firing

I'm trying to create an app that is similar to SnapChat when it takes videos. You are supposed to hold down a button to start taking a video and then release it when you are done. I'm trying to implement a timeout feature after 7 seconds and also a…
kbunarjo
  • 1,277
  • 2
  • 11
  • 27
0
votes
1 answer

Mixing NSThreads and NSTimer to update a view

I want to make an app to make appear and disappear circles on screen. Circles are enlarged on TouchesBegan and smaller on touchesEnd. I'm able to do it on ONE circle but i want to do that everywhere the user touch the screen. I know i have to work…
mickcoco
  • 1
  • 3
0
votes
2 answers

Retrieve images asynchronously using UISlider in iPhone

How do I retrieve images asynchronously and put it on UIImageView in iPhone programming ? Till now I was doing it synchronously, but the delay in retrieving the images is more, hence I would like to take the faster approach. I used NSTimer &…
suse
  • 10,503
  • 23
  • 79
  • 113
0
votes
2 answers

Is this NSTimer dealloc acceptable or will it produce an unexpected error?

I was duplicating my code, so I refactored it like this: -(void) dealloc { [self resetTimer]; [super dealloc]; } -(void) resetTimer { if( timer != nil ) { [timer invalidate]; } timer = nil; // set some other value to…
TigerCoding
  • 8,710
  • 10
  • 47
  • 72