我想在Swift doc中使用AFNetworking(這是一個必要的約束條件,否則我很樂意學習AlamoFire)。我與這裏做什麼掙扎,有人很新的雨燕:將Obj-C塊轉換爲Swift進行AFNetworking調用
- (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你看過我的留言嗎?該選擇不在我的控制之下。 – helloB