swift重载函数难道不是这么写的吗?
请各位大神自动忽略无关代码,关注函数定义,附图一张
func performOperation(operation: (Double,Double) -> Double)
{
if operandStack.count >= 2
{
displayValue = operation(operandStack.removeLast(), operandStack.removeLast())
enter()
}
}
func performOperation(operation: (Double) -> Double)
{
if operandStack.count >= 1
{
displayValue = operation(operandStack.removeLast())
enter()
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
因为你看到的视频,那个老头子用的是旧版xcode,新版xcode会检查了继承过来的object-c对象是否有重载了。老老头子用的是swift的重载特性,但object-c重载是不支持重载的。版本问题。
I found the answer.
Please check:
http://stackoverflow.com/questions/29457720/swift-compiler-error-which...
没有关键字。override。
http://www.cocoachina.com/bbs/read.php?tid=297461#1290696
这里讲的很清楚,继承的类不同的原因(UIViewController)
Objective-C does not support method overloading, you have to use a different method name. When you inherited UIViewController you inherited NSObject and made the class interopable to Obj-C. Swift on the other hand does support overloading, that's why it works when you remove the inheritance.
As it has already been answered, ObjC doesn't support method overloading (two methods with the same name) and In swift 2 under Xcode 7 there are two options to solve this kind of problems. One option is to rename the method using the attribute:
another option to solve this problem in Xcode 7+ is by applying @nonobjc attribute to any method, subscript or initialiser