However moving the anOption() function out of the enum type results in an error:
enum SampleEnum {
case anOption
func process() {
switch self {
case .anOption: anOption() // Enum case 'anOption' cannot be used as an instance member
}
}
}
fileprivate func anOption() {
// stuff
}
I'm curious if this is intentional behavior here or a bug of some kind? (Feels like a bug to me, tbh.)
I don’t know if it is intentional, but the compiler always finds static members first and prefers them over the global scope, resulting in errors.
var property = 0
struct Structure {
static var property = 0
func useProperty() {
property = 1 // Static member 'property' cannot be used on instance of type 'Structure'
}
}
What you can do is tell it where to look explicitly: