I can't figure out for the life of me why Xcode is throwing the error "Extra argument 'selector' in call." The method signature is fine and there is no extra 'selector' argument. Also, the auto complete brings the method up but Option-clicking on scheduledTimerWithTimeInterval says "No Quick Help" and the font is black instead of purple as if the compiler is not recognizing it. Here is the code:
我搞不懂为什么Xcode会抛出"额外参数" selector "方法签名很好,并且没有额外的“选择器”参数。此外,自动补全将打开方法,但是在scheduledTimerWithTimeInterval上单击选项会显示“没有快速帮助”,字体是黑色而不是紫色的,就好像编译器没有识别它一样。这是代码:
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var timerLabel: UILabel!
@IBOutlet weak var startButton: UIButton!
@IBOutlet weak var stopButton: UIButton!
var timer = NSTimer()
override func viewDidLoad() {
super.viewDidLoad()
startButton.layer.cornerRadius = 5.0
stopButton.layer.cornerRadius = 5.0
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func didPressStartButton(sender: AnyObject) {
timer = NSTimer.scheduledTimerWithTimeInterval(1.0, target: self, selector:Selector("updateTimeLabel"), userInfo: NSDate(), repeats: TRUE)
}
func updateTimerLabel() {
}
}
2 个解决方案
#1
2
Try true
instead of TRUE
. TRUE
is not defined in Swift, so the call does not compile. Swift errors are arcane - it often doesn't get the correct point of failure.
尝试真实而不是真实。TRUE不是在Swift中定义的,所以调用不会编译。迅速的错误是不可思议的——它往往没有得到正确的失败点。
timer = NSTimer.scheduledTimerWithTimeInterval(1.0, target: self, selector:Selector("updateTimeLabel"), userInfo: NSDate(), repeats: true)
works fine in Playground.
发挥的作用很好,在操场。
Update It's probably worth pointing out, too, that the Selector()
'function' is redundant - the string name of the function - "updateTimeLabel"
in this case - works equally well.
更新它可能也值得指出,选择器()“函数”是冗余的——在本例中,函数的字符串名称“updateTimeLabel”也同样有效。
#2
0
I also received this error when I had an invalid argument in the first parameter like this:
当我在第一个参数中有一个无效的参数时,我也收到了这个错误:
var delayHighlight = 2
var theDelay = fastPlay ? 0.0 : delayHighlight
if playerRank > aiRank {
var timer = NSTimer.scheduledTimerWithTimeInterval(theDelay,target:self,selector:"showPlayerOutline",userInfo:nil,repeats:false)
}
The problem was because the delayHighlight was being seen as an integer and therefore, the variable theDelay too was seen as an integer. Change first line to:
问题在于,delayHighlight被视为一个整数,因此,变量theDelay也被视为一个整数。第一行更改为:
var delayHighlight = 2.0
So, if this is not your problem I suggest looking at each parameter to see if it's the correct type.
所以,如果这不是你的问题,我建议查看每个参数,看看它是否是正确的类型。
#1
2
Try true
instead of TRUE
. TRUE
is not defined in Swift, so the call does not compile. Swift errors are arcane - it often doesn't get the correct point of failure.
尝试真实而不是真实。TRUE不是在Swift中定义的,所以调用不会编译。迅速的错误是不可思议的——它往往没有得到正确的失败点。
timer = NSTimer.scheduledTimerWithTimeInterval(1.0, target: self, selector:Selector("updateTimeLabel"), userInfo: NSDate(), repeats: true)
works fine in Playground.
发挥的作用很好,在操场。
Update It's probably worth pointing out, too, that the Selector()
'function' is redundant - the string name of the function - "updateTimeLabel"
in this case - works equally well.
更新它可能也值得指出,选择器()“函数”是冗余的——在本例中,函数的字符串名称“updateTimeLabel”也同样有效。
#2
0
I also received this error when I had an invalid argument in the first parameter like this:
当我在第一个参数中有一个无效的参数时,我也收到了这个错误:
var delayHighlight = 2
var theDelay = fastPlay ? 0.0 : delayHighlight
if playerRank > aiRank {
var timer = NSTimer.scheduledTimerWithTimeInterval(theDelay,target:self,selector:"showPlayerOutline",userInfo:nil,repeats:false)
}
The problem was because the delayHighlight was being seen as an integer and therefore, the variable theDelay too was seen as an integer. Change first line to:
问题在于,delayHighlight被视为一个整数,因此,变量theDelay也被视为一个整数。第一行更改为:
var delayHighlight = 2.0
So, if this is not your problem I suggest looking at each parameter to see if it's the correct type.
所以,如果这不是你的问题,我建议查看每个参数,看看它是否是正确的类型。