function overloading in swift [duplicate]

给你一囗甜甜゛ 提交于 2019-12-08 12:57:45

问题


I am trying to create two methods with the following arguments but the compiler is complaining that they are ambiguous. I am following a youtube series to learn Swift and it seems to be fine in the video there. What am I missing?

func performOperation(operation: Double -> Double){

func performOperation(operation:(Double, Double)->Double){


回答1:


It seems you may be running into the same problem mentioned in this reddit thread. It looks like the solution may just be to rename your functions, due to a clash with inherited with Objective C methods.

e.g.

func myPerformOperation(operation: Double -> Double){

func myPerformOperation(operation:(Double, Double)->Double){

(These aren't ideal names—they should be more descriptive—but you get the idea.)



来源:https://stackoverflow.com/questions/32687503/function-overloading-in-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!