I'm migrating some code originally written in Swift2 to Swift4. I've completed the Swift3 intermediate upgrade and am hitting some errors in Xcode9 regarding some user defined enum uses outside their source file.
Consider the following partial project structure...
Project
--EnumDefs
----ExceptionTypes.swift
--UI
----UseExceptions.swift
ExceptionTypes.swift
enum MyError : Error {
case err1
case err2
}
...
UseExceptions.swift
...
do {
...
} catch MyError.err1(let e) {
print("\(e)")
} catch let e {
print("\(e)")
}
...
I've also tried the variant syntax I've seen online of
catch let e as MyError.err1 {
still no luck, I'm seeing the compiler error:
Enum element 'err1' is not a member type of 'MyError'
I'm tried making the MyError scope to be defined public
which didn't work. I get a sense that I may be missing an import or something. I'm not sure if it matters but Autocomplete
in Xcode from the UseExceptions.swift file does recognize when I begin typing MyError.
Is there anything special to using definitions between swift files across a sibling directory like shown above? Or is there something else wrong here with the way Swift 4 deals with exception handling?