gpt4 book ai didi

Swift 3 - 如何将回调函数定义为参数

转载 作者:搜寻专家 更新时间:2023-10-31 08:16:18 25 4
gpt4 key购买 nike

想用 Alamofire 创建全局 http 请求函数/扩展就像是

function Request(requestPath:String, requestParams:Any, onComplate:Void) {
// stuff here, when async request complate i want to call onComplate function
// like C# method.Invoke() or func.Invoke()
}

最佳答案

你可以只传递闭包(函数)作为参数

swift
func request(requestPath:String, requestParams:Any, callback:((Result) -> Void)) {
...
}

Result 将是您的响应类型。

关于Swift 3 - 如何将回调函数定义为参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41090729/

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