gpt4 book ai didi

iOS - 在 Swift 中添加 Void SuccessCallback block

转载 作者:行者123 更新时间:2023-11-30 13:43:01 25 4
gpt4 key购买 nike

我对 Swift 还很陌生。如何定义具有 VOID 成功回调 block 和错误回调 block 的函数?我不需要在成功时传递任何对象,但我确实需要知道我的错误。

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

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

我想完成这样的事情,但我不确定我的语法是否正确:

func validateNewItemWithDescription(description: String, quantity: Int, successCallback: () ->(Void), errorCallback: (errorString: String) ->())
{

}

最佳答案

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

func parseCommand (inText: String) -> CommandParseResult

使用 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
}

关于iOS - 在 Swift 中添加 Void SuccessCallback block ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35332326/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com