Swift 2.1 selector Swift 2.2# selector

Asked 2 years ago, Updated 2 years ago, 74 views

Source code written with the intention of Swift 2.2.

timer=NSTimer.scheduledTimerWithTimeInterval(0.1,self,selector:#selector(ViewController.timeCheck(_:))),userInfo:nil,repeats:true)}

This will result in an error.

This error did not appear in Swift 2.1.

The following sources did not appear in Swift 2.1.

timer=NSTimer.scheduledTimerWithTimeInterval (0.1, target:self, selector:Selector("timeCheck:"), userInfo:nil, repeats:true)

Where and how should I fix it?

swift2

2022-09-30 21:16

1 Answers

The second argument of the scheduledTimerWithTimeInterval() method is unlabeled if the code is not miswritten.
This is one of the signature methods on the argument label, so if you forget to write it, it becomes a different method.

timer=NSTimer.scheduledTimerWithTimeInterval (0.1, target:self, selector:#selector(ViewController.timeCheck(_:), userInfo:nil,repeats:true)

^You must write 0.1, target:self,selector:... as shown above.


2022-09-30 21:16

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.