【发布时间】:2016-12-05 21:19:39
【问题描述】:
我正在尝试在 Swift 文档中使用 AFNetworking(这是必要的约束,否则我很想学习 AlamoFire)。作为一个对 Swift 很陌生的人,我正在为在这里做什么而苦苦挣扎:
- (nullable AFHTTPRequestOperation *)GET:(NSString *)URLString
parameters:(nullable id)parameters
success:(nullable void (^)(AFHTTPRequestOperation *operation, id responseObject))success
failure:(nullable void (^)(AFHTTPRequestOperation * __nullable operation, NSError *error))failure;
特别是,我不清楚如何处理故障块。这是我的尝试:
manager.GET(
"random_url",
parameters: [...random parameters...],
success: { (operation: AFHTTPRequestOperation!,
responseObject: AnyObject!) in
print("JSON: " + responseObject.description)
},
failure: { (operation: AFHTTPRequestOperation!, error: NSError!) in
print("there was an error")
}
)
我的failure 块出现错误:
Cannot convert value of type '() -> ()' to expected argument type '((AFHttpRequestOperation?, NSError) -> Void)?'。
如果人们能告诉我上面哪里出错了,我将不胜感激。非常感谢。
【问题讨论】:
-
@PEEJWEEJ 你看我的信息了吗?这个选择不在我的控制范围内。
标签: swift afnetworking objective-c-blocks