SwiftUI: define view appearances with protocols

89 views Asked by At

New to SwiftUI, I have seen that all UI components are now protocols or structs.

What I enjoy about protocols is the fact that I can combine them without needing inheritance, unlike object-oriented programming.

But then, I was wondering, how can I combine multiple view appearances, let's say I'd have a BlueView protocol that would define a view with a blue background, and a RoundedCorner protocol defining a view with rounded corners.

How can I do something like this:

MyView: View, BlueView, RoundedCorner { ...

In order not to have to set these lines of code in every view of my app?

Color.blue
.cornerRadius(8)
...

Thank you for your help

0

There are 0 answers