Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/111.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iOS-在Swift中添加一个Void SuccessCallback块_Ios_Swift_Closures - Fatal编程技术网

iOS-在Swift中添加一个Void SuccessCallback块

iOS-在Swift中添加一个Void SuccessCallback块,ios,swift,closures,Ios,Swift,Closures,我对斯威夫特很陌生。如何定义具有无效成功回调块和错误回调块的函数?我不需要在成功时传递任何对象,但我需要知道我的错误 使用传递对象的成功和错误回调块的函数示例: func searchForTweetsWithKeyword(searchString: String, geoCodeParameter: String, successCallback: (tweets :[Tweet]) ->(), errorCallback: (errorDictionary: Dictionary&l

我对斯威夫特很陌生。如何定义具有无效成功回调块和错误回调块的函数?我不需要在成功时传递任何对象,但我需要知道我的错误

使用传递对象的成功和错误回调块的函数示例:

func searchForTweetsWithKeyword(searchString: String, geoCodeParameter: String, successCallback: (tweets :[Tweet]) ->(), errorCallback: (errorDictionary: Dictionary<String, String>) ->()) {
    ...do stuff
}

您确实需要两个回调块吗?打个电话怎么样:

func parseCommand (inText: String) -> CommandParseResult
使用命令解析结果:

enum CommandParseResult{
case ValidCommand (Command)
case ErrorResponse (String) }
然后处理类似于:

        var validCommand: Command?
        let commandResult = self.myDictionary.parseCommand(textCommand)
        switch commandResult
        {
            case .ErrorResponse (let errorResponse):
                completionMessage = errorResponse.stringByReplacingCaseFormat("<Person>", withString: self.currentPerson)
            case .ValidCommand (let returnedCommand):
                validCommand = returnedCommand
        }
var validCommand:命令?
让commandResult=self.myDictionary.parseCommand(textCommand)
开关命令结果
{
案例错误响应(let ErrorResponse):
completionMessage=errorResponse.stringByReplacingCaseFormat(“,带字符串:self.currentPerson)
case.ValidCommand(让returnedCommand):
validCommand=returnedCommand
}

()->()可以吗?那么
验证WitemWithDescription
有什么问题吗?它有两个回调块,其中一个是Void。您还可以使用(作为一个选项)
()->()
,因为Void是一个空元组-
()
(Void)->()也正确吗?@Rafi,同样,但您应该决定什么对您最合适。最流行的样式是使用()->Void。看,拉菲,你为什么不自己试试看:)这是最好的学习方法。
        var validCommand: Command?
        let commandResult = self.myDictionary.parseCommand(textCommand)
        switch commandResult
        {
            case .ErrorResponse (let errorResponse):
                completionMessage = errorResponse.stringByReplacingCaseFormat("<Person>", withString: self.currentPerson)
            case .ValidCommand (let returnedCommand):
                validCommand = returnedCommand
        }