struct Foo: ExpressibleByStringLiteral {
init(stringLiteral value: String) /* throws :( not allow? */ {
guard value == "good" else {
// how to fail?
// neither failable or throws seem to be allowed?
fatalError("Ha? what to do here, want to fail somehow, not crash!!!")
}
// okay, we are good ...
}
}
basically Foo init by string literal only works for some string values, else it needs to fail somehow.
fatalError is the best you can do for now. Hopefully optimizer improvements will eventually allow literals to be evaluated as compileātime constants, which would elevate the fatalError to an outright build failure.