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

Not able to pass Timer.sheduledTimer with parameters

basicPidTimer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(self.pidsUsage(indexPid:)), userInfo: pidsIndex, repeats: false) //calling method bellow but not triggering anyhelp? @objc func pidsUsage(indexPid : Int){ }
djt
  • 1
  • 5
0
votes
1 answer

Objective-C NSMethodSignature issue!

Basically I'm using "instanceMethodSignatureForSelector" as part of the construction of an NSTimer. My problem is that the below NSMethodSignature is always set to "Nil". NSMethodSignature *signature = [[self class]…
Jeff
  • 2,017
  • 3
  • 15
  • 8
0
votes
2 answers

Multiple Timer in containerView swift 4 xcode

I have one main ControllerView with two container view on top of each other (containerA on top of ContainerB). both containerView has a ControllerView. I am running a timer in each ContainerView. problem I am facing is that when I hide ContainerB to…
0
votes
2 answers

NSTimer retainCount is not zero after invalidate

I did some test and confused with the result. NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(runTimer) userInfo:nil repeats:YES]; NSLog(@"Timer Retain count is %ld", CFGetRetainCount((__bridge…
0
votes
1 answer

NSTime create a timeInterval

I have the following code in my application in the method updateLabel2: timeLeft = [[NSDate date] timeIntervalSinceDate:[[NSUserDefaults standardUserDefaults] objectForKey:@"lastDate"]]; [[self timer] setText:[NSString stringWithFormat:@"Time…
joshim5
  • 2,292
  • 4
  • 28
  • 40
0
votes
1 answer

How to invalidate NSTimer inside tablecell

I am using following method to delete table cell but it doesn't invalidate timer which is running inside that cell. [tableView deleteRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:index inSection:indexPath.section]]…
Vishwanath Deshmukh
  • 619
  • 1
  • 10
  • 32
0
votes
1 answer

how can I make a counter or timer using NSDate or NSCalendar?

I am new to iphone development, I am developing an application, which takes restaurant order data (Name of Restaurant and order price) and save to an array and display on another UITable, but now I want to start a timer such as Royal Taj $35 1 hour,…
Chatar Veer Suthar
  • 15,541
  • 26
  • 90
  • 154
0
votes
1 answer

userinfo in NSTimer iOS4

I want to pass some data to the fire method.So I use the 'userInfo' I did like this: struct MyStruct* userinfo = malloc(sizeof(struct MyStruct)); userinfo->a = 1; userinfo->b = 2; NSTimer *myTimer = [NSTimer scheduledTimerWithInterval:0.05…
Rafer
  • 1,170
  • 2
  • 10
  • 15
0
votes
1 answer

Unpause this NSTimer?

I am pausing an NSTimer like so: - (IBAction)pause { pauseStart = [[NSDate dateWithTimeIntervalSinceNow:0] retain]; previousFiringDate = [stopmusictimer fireDate]; NSDate *date = [NSDate distantFuture]; [stopmusictimer…
Rick
  • 83
  • 6
0
votes
2 answers

How to invalidate timer outside ViewDidLoad

I'm stuck with invalidating timer outside of ViewDidLoad. Tried to declare timer globally, but got a SIGABRT error. What am am I missing? override func viewDidAppear(_ animated: Bool) { let timer = Timer(timeInterval: 3, …
Max Kraev
  • 740
  • 12
  • 31
0
votes
0 answers

Scheduled timer from AppDelegate: too long to start

I need to load in memory a lot of different info, and I want to know which way is faster: simple tsv file, or realm database. For that I'm trying to implement scheduled timer in AppDelegate. This timer should start as soon as possible, and it should…
lithium
  • 1,272
  • 1
  • 14
  • 28
0
votes
2 answers

How to set progress bar With timer after view controller loaded

I m using timer on circular progress bar and taken NSDate property in interface (tested also taking in viewWillAppear) but when viewController loads it show starting from 27 seconds remain, while i have set its value to 30 seconds. My scenario is, a…
MRizwan33
  • 2,723
  • 6
  • 31
  • 42
0
votes
0 answers

How to call an action after an alert closed in iOS

I have a subclass of UILabel called AlertLabel AlertLabel.h #import @interface AlertLabel : UILabel - (id)initWithFrame:(CGRect)frame; - (void)alertTitle:(NSString *)string; @end AlertLabel.m - (id)initWithFrame:(CGRect)frame { …
markl
  • 7
  • 5
0
votes
2 answers

Question about NSTimer and retain

This code works well @property (nonatomic, retain) NSTimer *timer; self.timer = [[NSTimer timerWithTimeInterval:kAdsAppearTimeInterval target:self selector:@selector(timerFired:) userInfo:nil repeats:NO] retain]; this code get CFRelease . But why?…
Voloda2
  • 12,359
  • 18
  • 80
  • 130
0
votes
1 answer

How to update tableviewcell in realtime when the corresponding secondViewController changes

I am creating a simple to-do app where you can create a task and when you tap on the tableviewcell it takes you to the secondVC(EditVC) where you can edit the task and also set reminder for it. When the reminder is set a bellicon appears in the…
Osama Naeem
  • 1,830
  • 5
  • 16
  • 34