I\'ve got the following code, which makes it possible to use the UIKit\'s UIScrollView
in my SwiftUI code. It can be pasted in a new SwiftUI project.
I disagree with your assertion that the enum
should be nested inside the class for the following reasons:
enum
is intended to be used both inside and outside of the class, with a generic type being required in order to use it.enum
does not make use of, and therefore has no dependency on, the generic Content
type.enum
would be obvious.If you really want to nest the enum
definition, I would suggest the following:
content
member to be of AnyView
type,init
functions generic and store the return values of the given view builders into type-erased views, like so:init(@ViewBuilder content: () -> Content) {
self._action = Binding.constant(Action.idle)
self.content = AnyView(content())
}
init(action: Binding, @ViewBuilder content: () -> Content) {
self._action = action
self.content = AnyView(content())
}
Of course, with this approach, you will:
So it depends what you value more in this case... Ahhh, tradeoffs...