Can I recommend library users to use `@unknown default` for my public enum?

I am developing a swift package, and have enums like this.

public enum Message {
    case hello
    case goodbye

    var somePropertyA: String { ... }
    var somePropertyB: Int { ... }
    // ...
}

What I want to do is avoiding source breakage caused by adding cases to the Message. I'd like users to treat future-added case in some nice way, like print("Unsupported case!").

So I'd like to recommend library users to use @unknown default for matching. However, as far as I understand, compiler suggestion for @unknown default is only shown when the library is in library evolution mode, and the mode is recommended only for binary according to the official blog.

So my question is

  • Is it possible to make suggestion for @unknown default shown without library evolution mode
  • If not, then what can I do to avoid such source breakage. I'm currently considering structs + static property pattern, but I'm being attracted by the ability of enum that allows exhaustive matching.
1 Like