You are viewing a single comment's thread. Return to all comments →
A better approach would be:
// ErrorType Protocol. enum ConversionError: ErrorType { case NotAnInt } // A function that "throws". func stringToInteger(stringValue: String) throws -> Int { guard Int(stringValue) != nil else { throw ConversionError.NotAnInt } return Int(stringValue)! } // Input. let inputString = readLine()! // Logic. do { try print(stringToInteger(inputString)) } catch { print("Bad String") }
But even that is not accepted.
This exercise is broken for Swift.
Seems like cookies are disabled on this browser, please enable them to open this website
Day 16: Exceptions - String to Integer
You are viewing a single comment's thread. Return to all comments →
A better approach would be:
But even that is not accepted.
This exercise is broken for Swift.