Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why is performSelector not present in swift

Tags:

ios

swift

apparently the following is not available in swift anymore:

[self performSelector:@selector(onFlip) withObject:nil afterDelay:0.3];

why is this the case if the following is still present:

NSObject.cancelPreviousPerformRequestsWithTarget(self, selector: singleTapSelector, object: nil)

doesn't nsobject.cancel work with performSelector? why have the cancel functionality but not the perform functionality?

like image 719
duxfox-- Avatar asked Dec 21 '14 20:12

duxfox--


People also ask

What is performSelector in Swift?

Swift is statically typed so the performSelector: methods are to fall by the wayside. Instead, use GCD to dispatch a suitable block to the relevant queue — in this case it'll presumably be the main queue since it looks like you're doing UIKit work.

How do you call a selector in Swift?

The usage of this "ValueAnimator" would be similar to a normal Timer/NSTimer, in that you pass a "selector" as an argument and that selector is called each time the ValueAnimator fires: [In Parent Class]: // { ... let valueAnimatorTest = ValueAnimator(durationInSeconds: 10, selector: #selector(self.


1 Answers

Use

NSTimer.scheduledTimerWithTimeInterval(delay, target: self, selector: "onFlip", userInfo: nil, repeats: false)

instead. No idea why the other one is not available.

like image 132
qwerty_so Avatar answered Sep 27 '22 19:09

qwerty_so