Hello, I have a situation where Xcode 7 beta is complaining that "Errors thrown from here are not handled because the enclosing catch is not exhaustive." But I'm confused because, to me, it does appear that my cases are exhaustive, covering all of the one cases in my ErrorType enum.
Here's my code:
import UIKit
protocol SearchItemView {
var center: CGPoint { get }
var radius: CGFloat { get }
var color: UIColor { get }
init(center: CGPoint, radius: CGFloat, color: UIColor)
}
enum SearchViewModelError: ErrorType {
case InvalidClassName // only one error case
}
class SearchViewModel {
private var searchItemViewClassName: String
private var searchItems: [SearchItemView] = []
init(searchItemViewClassName: String) {
self.searchItemViewClassName = searchItemViewClassName
do {
try createSearchItemView() // Xcode error here about lacking exhaustive cases; can't build and run
} catch SearchViewModelError.InvalidClassName { // covers the one error case
}
}
func createSearchItemView() throws -> SearchItemView {
guard let searchItemView: SearchItemView = NSClassFromString(searchItemViewClassName) as? SearchItemView else {
throw SearchViewModelError.InvalidClassName // only one possible error thrown
}
return searchItemView
}
}
I can eliminate the error by adding an extra superfluous catch to catch anything else: "catch {}", after the first catch I have.