将XCode更新为6.3 Function signature '(TimeInterval) -> ()' is not compatible with expected type '(value: TimeInterval) -> ()'
后,我收到错误。
代码如下:
//in `editView` property signature
var changeAction: ((value: TimeInterval)->())?
//usage
editView?.changeAction = { [unowned self] (newValue: EditDateView.TimeInterval) in
self.presentTime = newValue
wPopup?.dismiss(true)
}
我找到了一个解决方案:
@IBAction func timePressed() {
// some code
weak var wPopup = popup
func timeChanged(#value: EditDateView.TimeInterval) {
self.presentTime = value
wPopup?.dismiss(true)
}
editView?.changeAction = timeChanged
}
或者:
@IBAction func timePressed() {
// some code
weak var wPopup = popup
editView?.changeAction = timeChanged(wPopup)
}
func timeChanged(wPopup: KLCPopup?)(value: EditDateView.TimeInterval) {
self.presentTime = value
wPopup?.dismiss(true)
}
但这可能会处理自我引用,不确定。
答案 0 :(得分:0)
看起来你可能会将闭包参数的类型与调用时提供给闭包的参数混淆。假设TimeInterval
是有效类型,它看起来像这样。
editView?.changeAction = { [unowned self] (newValue: TimeInterval) in
self.presentTime = newValue
wPopup?.dismiss(true)
}
假设EditDateView.TimeInterval
是TimeInterval
类型的有效实例,您可以这样称呼。
editView?.changeAction?(value: EditDateView.TimeInterval)