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

Swift 3 – 如何将回调函数定义为参数,第1张

概述想要用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 想要用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()}
@H_301_14@解决方法 您可以将闭包(函数)作为参数传递

swiftfunc request(requestPath:String,callback:((Result) -> VoID)) {     ... }

结果将是您的回复类型.

总结

以上是内存溢出为你收集整理的Swift 3 – 如何将回调函数定义为参数全部内容,希望文章能够帮你解决Swift 3 – 如何将回调函数定义为参数所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/web/1010213.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存