Last active
October 27, 2015 16:40
-
-
Save JRHeaton/773c9de5b2ff6be9fb40 to your computer and use it in GitHub Desktop.
Swift compiler does not detect the `try` expression given to the Result initializer unless broken up into its own expression
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// warning: 'catch' block is unreachable because no errors are thrown in 'do' block | |
public func requestJSON<ModelType: MTLModel>(target: CocoaBlocAPI) -> SignalProducer<ModelType, NSError> { | |
return tryGetJSONObjectForKey(requestJSON(target), key: "data") | |
.attemptMap { (value: [NSObject:AnyObject]) -> Result<ModelType, NSError> in | |
do { | |
return Result(try MTLJSONAdapter.modelOfClass(ModelType.self, fromJSONDictionary: value) as! ModelType) | |
} | |
catch let error as NSError { | |
return .Failure(error) | |
} | |
} | |
} | |
// no warnings | |
public func requestJSON<ModelType: MTLModel>(target: CocoaBlocAPI) -> SignalProducer<ModelType, NSError> { | |
return tryGetJSONObjectForKey(requestJSON(target), key: "data") | |
.attemptMap { (value: [NSObject:AnyObject]) -> Result<ModelType, NSError> in | |
do { | |
let p = try MTLJSONAdapter.modelOfClass(ModelType.self, fromJSONDictionary: value) as! ModelType | |
return Result(p) | |
} | |
catch let error as NSError { | |
return .Failure(error) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment