nstimer

NSTimer vs CACurrentMediaTime()

喜夏-厌秋 提交于 2019-11-29 23:04:20
So I'm amidst my first iOS game and am struggling with how to go about the best way to integrate object movement. The game relies heavily on fast moving objects and constant, fast user input changes. As such, I'm trying to have object integration and the constraint solver run as quickly and accurately as possible (to minimize user input change in between successive game loop calls). More specifically, I'm unsure of the capabilities of the NSTimer class and CACurrentMediaTime() function. It's hard to test empirically because I'm not sure which have the larger error. For example, using an

Using NSTimer in swift playground [duplicate]

谁都会走 提交于 2019-11-29 22:07:45
问题 This question already has answers here : How do I run Asynchronous callbacks in Playground (8 answers) Closed 4 years ago . I'd like to know how to use an NSTimer inside a Swift Playground. This question has been asked before, but none of the answers actually answered the question. Here's my Playground code: import Foundation class MyClass { func startTimer() { NSTimer.scheduledTimerWithTimeInterval(0.5, target: self, selector: "onTimer:", userInfo: nil, repeats: true) } func onTimer(timer

Send Local Notifications while App is running in the background Swift 2.0

纵饮孤独 提交于 2019-11-29 21:12:39
问题 I am trying to send the user a 'Push Notification style' Alert when the user minimizes the app (by clicking on the iPhone's Home Button or by locking the phone as well). My app continuously parses an XML file (every 10 seconds) and I want the app to continue running so that it sends the user a Local Notification once some condition has been met in my program, even after the user has minimized the app or locked their phone. I've bounced around from tutorials and everyone seems to 'schedule' a

NSTimer Too Slow

偶尔善良 提交于 2019-11-29 18:16:31
I have seen multiple questions similar to this; however, none of them resolved my problem. My timer is simply going too slowly. I am only using an interval of 0.01 seconds. Here is my code: @IBOutlet var timerLabel: UILabel! var miliseconds = 0 var seconds = 0 func updateLabel() { if miliseconds == 0 { timerLabel.text = "\(seconds).00" } else if miliseconds < 10 { timerLabel.text = "\(seconds).0\(miliseconds)" } else { timerLabel.text = "\(seconds).\(miliseconds)" } } var timer = NSTimer() func updateTime() { miliseconds++ if miliseconds == 100 { miliseconds = 0 seconds++ } updateLabel() }

Spawning a Spritekit node at a random time

帅比萌擦擦* 提交于 2019-11-29 15:31:12
问题 I'm making a game where I have a node that is spawning and falling from the top of the screen. However I want to make the nodes spawn at random time intervals between a period of 3 seconds. So one spawns in 1 second, the next in 2.4 seconds, the next in 1.7 seconds, and so forth forever. I am struggling with what the code should be for this. Code I currently have for spawning node: let wait = SKAction.waitForDuration(3, withRange: 2) let spawn = SKAction.runBlock { addTears() } let sequence =

NSTimer.scheduledTimerWithTimeInterval in Swift Playground

南楼画角 提交于 2019-11-29 14:02:40
All the examples I've seen on using the "NSTimer.scheduledTimerWithTimeInterval" within Swift show using the "target: self" parameter, but unfortunately this doesn't work in Swift Playgrounds directly. Playground execution failed: <EXPR>:42:13: error: use of unresolved identifier 'self' target: self, Here's an example referenced above that results in the error: func printFrom1To1000() { for counter in 0...1000 { var a = counter } } var timer = NSTimer.scheduledTimerWithTimeInterval(0, target: self, selector: Selector("printFrom1To1000"), userInfo: nil, repeats: false ) timer.fire() You really

How to pass arguments when calling function with timer in objective c

房东的猫 提交于 2019-11-29 12:16:17
-(void)setX:(int)x andY:(int)y andObject:(Sprite*)obj { [obj setPosition:CGPointMake(x,y)]; } Now, I want to call above method, using following timer. [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector() userInfo:nil repeats:NO]; What to set Here? How to Pass arguments? (as per my knowledge - selector specifies only the method to invoke) Dave DeLong You'll need to used +[NSTimer scheduledTimerWithTimeInterval:invocation:repeats:] instead. By default, the selector used to fire a timer takes one parameter. If you need something other than that, you have to create an

What is difference between self.timer = nil vs [self.timer invalidate] in iOS?

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-29 09:49:39
Can anyone explain me self.timer=nil vs [self.timer invalidate] ? What exactly happens at the memory location of self.timer ? In my code self.timer=nil doesn't stops the timer but [self.timer invalidate] stops the timer. If you require my code I will update that too. Once you have no need to run timer, invalidate timer object, after that no need to nullify its reference. This is what Apple documentation says: NSTimer Once scheduled on a run loop, the timer fires at the specified interval until it is invalidated. A non-repeating timer invalidates itself immediately after it fires. However, for

swift invalidate timer doesn't work

我的未来我决定 提交于 2019-11-29 09:14:19
I have this problem for a few days now and I don't get what I am doing wrong. My application is basically just creating some timers. I need to stop them and create new ones. But at the moment stopping them doesn't work. self.timer = NSTimer.scheduledTimerWithTimeInterval(timeInterval, target:self, selector: "timerDidEnd:", userInfo: "Notification fired", repeats: false) That's my timer func timerDidEnd(timer:NSTimer){ createUnrepeatedAlarmWithUpdateInterval() } Because my timer didn't want to stop I am currently using the unrepeated timer and start it myself after it stopped. func stopAlarm()

iOS Not the typical background location tracking timer issue

断了今生、忘了曾经 提交于 2019-11-29 05:23:29
i'm developing a sample app that tracks the user's position in background, but i don't want to leave the location service always enabled, but something in my timer does not behave properly. My idea was that every x minutes, the service goes on, and when it have a correct new location it is released again, now is set to 10 seconds just for testing. (Significant LocationChange did not the trick, not accurated enough) I was searching a lot (iOS Dev center + StackOverflow) and found the "new" background location features, that allows you to run code over 10 minutes after going to background, using