gpt4 book ai didi

ios - 如何在 Swift 中使用闭包继承函数

转载 作者:行者123 更新时间:2023-11-29 00:55:05 27 4
gpt4 key购买 nike

我已经在我的 APIServices 类中定义了这个函数

typealias APIResponseOK = (data:NSDictionary, extra:NSDictionary) -> Void
typealias APIResponseError = (failure:Bool, code:NSString, message:NSString) -> Void

func getHttp(action:NSString, onResult:APIResponseOK, onError:APIResponseError) -> Void {

let strUrlRequst = String(format: "\(action)")

Alamofire.request(.GET, strUrlRequst).responseJSON { (responseData) -> Void in

if(responseData.result.error == nil){

if((responseData.result.value) != nil) {
let swiftyJsonVar = JSON(responseData.result.value!)

print("Response \(swiftyJsonVar)")

onResult(data: swiftyJsonVar.dictionaryObject!, extra: swiftyJsonVar.dictionaryObject!);
}
}
else{
onError(failure: true, code: "OM_ERR", message: (responseData.result.error?.localizedDescription)!);
}

}
}

现在我想在 ViewController 类中继承这个功能。我试过的是如下。

   apiServices.getHttp("Somename", onResult: (data:NSDictionary, extra:NSDictionary){

},
onError:(failure: Bool, code:NSString, message:NSString){


})

为什么我会收到此错误。请纠正我,我是 swift 的新手

enter image description here

最佳答案

apiServices.getHttp("Somename", onResult:{ data: NSDictionary, extra: NSDictionary in
// some
}, onError:{ failure: Bool, code: NSString, message: NSString in
// some
})

您应该检查所有 Apple Swift 文档,而不是先使用它。以及其他问题,例如为什么要在 Swift 中使用 NSString 或 NSDictionary。

关于ios - 如何在 Swift 中使用闭包继承函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37673983/

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