# UIViewRepresentables must be value types

At work, I inherited some SwiftUI code to maintain. The following code is simplified.

```swift
final class MySwiftUIViewWrappingUIView: UIViewRepresentable {
    // ...
}
```

The existing code works fine running on iOS 15. But running the same code on iOS 16 will lead to a runtime exception. Surprise 💣

`Fatal error: UIViewRepresentables must be value types: MySwiftUIViewWrappingUIView`

Apparently, the Apple team decided to align the behavior with types directly conforming to SwiftUI's `View` protocol. Code using a `final class` conforming to `View` will compile but will cause a runtime exception on iOS 15 and iOS 16.

We should all listen to Paul Hudson when he talks about [Why does SwiftUI use structs for views?](https://www.hackingwithswift.com/books/ios-swiftui/why-does-swiftui-use-structs-for-views)

> If you use a class for your view you might find your code either doesn’t compile or crashes at runtime. Trust me on this: use a struct.

The solution to the encountered problem above is simple.

```swift
struct MySwiftUIViewWrappingUIView: UIViewRepresentable {
    // ...
}
```

I wish I knew why my colleague chose a `final class` 🤔

Anyway, the key takeaway is that you <mark>must use a value type (</mark>`struct` <mark>or </mark> `enum`<mark>) for your SwiftUI Views and UIViewRepresentables</mark>.
