Apple introduced fancy new error handling in Swift 2
I'm working with project that uses AFNetoworking v2.x where AFHTTPRequestSerializer has 2 selectors:
- (NSMutableURLRequest *)requestWithMethod:(NSString *)method
URLString:(NSString *)URLString
parameters:(id)parameters DEPRECATED_ATTRIBUTE;
- (NSMutableURLRequest *)requestWithMethod:(NSString *)method
URLString:(NSString *)URLString
parameters:(id)parameters
error:(NSError * __autoreleasing *)error;
First is deprecated but second is converted automatically to first signature by Swift 2 compiler. Old fashioned method now doesn't allowed:
var error: NSError?
let request = self!.operationManager.requestSerializer.requestWithMethod(method, URLString: url?.absoluteString, parameters: params, error: error)
gives me a compile time error:
Cannot convert value of type 'NSError?' to expected argument type '()'
But brand new notation reduces selector with error processing to deprecated variant without it.
do {
let request = try
self!.operationManager.requestSerializer.requestWithMethod(method, URLString: url?.absoluteString, parameters: params)
} catch let error as NSError {
// ...
}
What is best practice in Swift 2 to solve this problem? Is there any way to specify certain selector in this situation?
UPD: More precise link on Swift 2 feature that become a reason of my problem. https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/BuildingCocoaApps/AdoptingCocoaDesignPatterns.html#//apple_ref/doc/uid/TP40014216-CH7-ID10