none
SW-R1025Using "none" as a member name in an enum may create ambiguity and confusion while working with optional values. This is because Optional.none
is a reserved keyword in Swift, and using it as a member name in an enum may conflict with that.
If you use "none" as a member name in an enum, it may lead to unexpected behavior when working with optional values. For example, consider the following code:
enum Result {
case success
case failure
case none
}
var result: Result = Result.none
print(result == .none) // This will print true
In the above example, result == .none
returns true despite assigning a Result
value.
To avoid this ambiguity and confusion, it is recommended to use a different name for the member in your enum instead of none
. For example, you can use unknown
or undefined
depending on the semantics of the member.
enum Result {
case success
case failure
case none
}
enum Result {
case success
case failure
case unknown
}