将 AFNetworking swift 2.3 mock 转换为 swift 3?
Convert AFNetworking swift 2.3 mock to swift 3?
我们正在尝试将 swift2.3 AFNetworking 模拟转换为 swift 3。这是 Swift 2.3 代码:
class MockAFHTTPRequestOperationManager : AFHTTPRequestOperationManager {
var capturedPOSTURL = ""
var capturedPOSTParameters: Dictionary<String, String> = [:]
internal override func post(_ URLString: String!, parameters: AnyObject!, success: ((AFHTTPRequestOperation?, AnyObject?) -> Void)!, failure: ((AFHTTPRequestOperation?, NSError?) -> Void)!) -> AFHTTPRequestOperation! {
capturedPOSTURL = URLString
capturedPOSTParameters = parameters as! Dictionary
return AFHTTPRequestOperation()
}
}
这是我们尝试的 swift 3 代码,但是当我们在 func POST
前面添加覆盖时出现编译错误:
func POST(URLString: String, parameters: AnyObject, success: (_ operation: AFHTTPRequestOperation, _ responseObject: AnyObject) -> Void, failure: (_ operation: AFHTTPRequestOperation, _ error: NSError) -> Void) -> AFHTTPRequestOperation {
return AFHTTPRequestOperation()
}
它表示该方法不会覆盖其超类中的任何方法。
这是我们要覆盖的 Objective-C 方法:
- (AFHTTPRequestOperation *)POST:(NSString *)URLString
parameters:(id)parameters
success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success
failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure;
我们正在使用 AFNetworking 2.5.1
我们如何使用 swift3 语法正确覆盖上面的 AFHTTPRequestOperationManager POST 方法?
这个有效:
override func post(_ URLString: String, parameters: Any, success: ((_ operation: AFHTTPRequestOperation, _ responseObject: Any) -> Void)! , failure: ((_ operation: AFHTTPRequestOperation, _ error: Error) -> Void)!) -> AFHTTPRequestOperation {
return AFHTTPRequestOperation()
}
我们正在尝试将 swift2.3 AFNetworking 模拟转换为 swift 3。这是 Swift 2.3 代码:
class MockAFHTTPRequestOperationManager : AFHTTPRequestOperationManager {
var capturedPOSTURL = ""
var capturedPOSTParameters: Dictionary<String, String> = [:]
internal override func post(_ URLString: String!, parameters: AnyObject!, success: ((AFHTTPRequestOperation?, AnyObject?) -> Void)!, failure: ((AFHTTPRequestOperation?, NSError?) -> Void)!) -> AFHTTPRequestOperation! {
capturedPOSTURL = URLString
capturedPOSTParameters = parameters as! Dictionary
return AFHTTPRequestOperation()
}
}
这是我们尝试的 swift 3 代码,但是当我们在 func POST
前面添加覆盖时出现编译错误:
func POST(URLString: String, parameters: AnyObject, success: (_ operation: AFHTTPRequestOperation, _ responseObject: AnyObject) -> Void, failure: (_ operation: AFHTTPRequestOperation, _ error: NSError) -> Void) -> AFHTTPRequestOperation {
return AFHTTPRequestOperation()
}
它表示该方法不会覆盖其超类中的任何方法。
这是我们要覆盖的 Objective-C 方法:
- (AFHTTPRequestOperation *)POST:(NSString *)URLString
parameters:(id)parameters
success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success
failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure;
我们正在使用 AFNetworking 2.5.1
我们如何使用 swift3 语法正确覆盖上面的 AFHTTPRequestOperationManager POST 方法?
这个有效:
override func post(_ URLString: String, parameters: Any, success: ((_ operation: AFHTTPRequestOperation, _ responseObject: Any) -> Void)! , failure: ((_ operation: AFHTTPRequestOperation, _ error: Error) -> Void)!) -> AFHTTPRequestOperation {
return AFHTTPRequestOperation()
}