I am writing a tool which accepts certain set of inputs, including some files, parses them, does error checking and if there are no errors then proceeds to do the actual work.
There are about 20 predefined errors with specific error strings in specification for which the tool does input verification.
I can do these error checks without using any data structure (I am new to swift land). But I am intrigued by use of enums and exploring if they make sense in this case.
So, I am planning to write something as follows:
enum ErrorCheck {
case incorrectFilePathProvided (code: Int, description: String)
case inputFileIsMissingVersionNumber (code: Int, description: String)
....
}
let errorIncorrectFilePathProvided = ErrorCheck.inputFileNotProvided(1, "User has provided incorrect input file")
....
static func validateInputParams(param1: String, param2: NSDictionary) -> NSArray {
var result: NSMutableArray = []
if !param1.hasPrefix("/Application") {
result.add([ErrorCheck.errorIncorrectInputFilePathProvided.code : ErrorCheck.errorIncorrectInputFilePathProvided.description])
}
if !param2["specificKey"] {
result.add([ErrorCheck.errorIncorrectInputFilePathProvided.code : ErrorCheck.errorIncorrectInputFilePathProvided.description])
}
}
Does this approach makes sense or is there more swifty way to do this?