According the Apple docs, the new NS_CLOSED_ENUM macro added for Swift 5 is unchangeable. How is this possible? Can't I just clean the build, add a value, and recompile my app?
Important
Once an enumeration is marked as closed, it's a binary- and source-incompatible change to add a new value. If you have any doubt about an enumeration gaining a private or additional public case in the future, use the NS_ENUM macro instead.
I was able to add a new value to our app and compile just fine (after updating the switch cases).
When you use
NS_CLOSED_ENUM, you are making a promise to consumers of your API that the enum will never change, either now in the future.Of course, there is nothing stopping you from making that change, but if you do, you've now broken that promise. As you said, it compiles fine after updating the switch cases.
If you declare it to be a closed enum you are telling all developers that they never have to worry about it changing. This is useful in Swift 5, which adds an
@unknown defaultconstruct inswitchstatements to handle unclosed enums.See this post for more information.