i am trying to implement some function to get Integer from somefunction using try catch in swift as
//Enum
enum LengthError: ErrorType {
case NoInt
case Default
}
// get Max length From Key else throws error
func getMaximumLength() throws -> Int? {
guard let length = Int(getStringForKey("KEY")) else {
throw LengthError.NoInt
}
return length
}
// This function
func getMaxLength() -> Int {
var maxLength: Int?
do {
maxLength = try getMaximumLength()
} catch LengthError.NoInt {
maxLength = 20
} catch LengthError.Default {
maxLength = 20
} catch {
maxLength = 20
}
return maxLength
}
but compiler showing error at getMaximumLength() func as "Thrown expression type 'String ' does not confirm to 'ErrorType'".
how to resolve this issue?
return maxLengthingetMaxLength()) and the functiongetStringForKey(_:)isn't defined. - Hamish