Callback function syntax in Swift

后端 未结 5 948
南旧
南旧 2020-12-08 10:12

I am attempting pass a function to another function and then have the passed function executed passing to it a variable.

Here is my code:

func showSt         


        
5条回答
  •  星月不相逢
    2020-12-08 10:32

    In the parameters for showStandardPrompt, you declare callback to have the type ()->(String), which is a function which takes no parameters and returns a String.

    You then call it with field.text! as a parameter, which obviously conflicts with the previously given type.

    You need to correct the type given to callback to take a String argument and return nothing:

    (String)->()
    

提交回复
热议问题