NSTimer with anonymous function / block?

You can make use of dispatch_after if you want to achieve something similar to NSTimer and block execution. Here is the sample code for the same: int64_t delayInSeconds = gameInterval; // Your Game Interval as mentioned above by you dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC); dispatch_after(popTime, dispatch_get_main_queue(), ^(void){ // Update your label here. }); … Read more

Xcode 7.3 / Swift 2: “No method declared with Objective-C selector” warning

Since Swift 2.2 / Xcode 7.3 there is a new way to use a selector: Selector(“funcName”) was changed to #selector(ClassName.funcName) Have a look at https://github.com/apple/swift-evolution/blob/master/proposals/0022-objc-selectors.md , tl;dr; Replace Selector(“Start”) with #selector(YOUR_CLASS.Start) where YOUR_CLASS = class of target in given context. If you don’t want to do it manually, Xcode provides easy fix itself by default, … Read more

Using an NSTimer in Swift

You can create a scheduled timer which automatically adds itself to the runloop and starts firing: Swift 2 NSTimer.scheduledTimerWithTimeInterval(0.5, target: self, selector: “timerDidFire:”, userInfo: userInfo, repeats: true) Swift 3, 4, 5 Timer.scheduledTimer(withTimeInterval: 0.5, target: self, selector: #selector(timerDidFire(_:)), userInfo: userInfo, repeats: true) Or, you can keep your current code, and add the timer to the runloop … Read more

Weak Reference to NSTimer Target To Prevent Retain Cycle

The proposed code: __weak id weakSelf = self; timer = [NSTimer scheduledTimerWithTimeInterval:30.0f target:weakSelf selector:@selector(tick) userInfo:nil repeats:YES]; has the effect that (i) a weak reference is made to self; (ii) that weak reference is read in order to provide a pointer to NSTimer. It won’t have the effect of creating an NSTimer with a weak reference. … Read more

Scheduled NSTimer when app is in background?

You shouldn’t solve this problem by setting a timer, because you’re not allowed to execute any code in the background. Imagine what will happen if the user restarts his iPhone in the meantime or with some other edge cases. Use the applicationDidEnterBackground: and applicationWillEnterForeground: methods of your AppDelegate to get the behavior you want. It’s … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)