Value enforcement for specific protocols

Starting in iOS 14.5, this rdar:62886135 is implemented:

Types conforming to any style protocol, such as ButtonStyle , ToggleStyle , are now enforced to be value types. Styles must be structures or enumerations, not classes, and conforming a class to a style protocol may trigger an assertion. This is the same restriction that the system has always enforced on types conforming to View . (62886135)


How is it implemented and is it possible to use this enforcement in custom libraries too?

Edit: It sounds like a runtime and not a compile-time assertion.

1 Like

You could probably make a tool with either jpsim/SourceKitten: An adorable little framework and command line tool for interacting with SourceKit. ( or apple/swift-syntax: SwiftPM package for SwiftSyntax library. ( and run it in the build phase.

1 Like