News for hackers. Stuff that matters.
Re:Static Types in SwiftUI by Razengan on Tuesday November 05, 2019 @06:20PM (#21457925)
> Your workaround is to use the AnyView type I guess.

Yes, I made the init generic instead of the type, and made the property an AnyView, but I've read that AnyView may decrease performance (probably because of reasons discussed in this post's article.)

Re:Static Types in SwiftUI by DelightOne on Tuesday November 05, 2019 @06:33PM (#21458052)
True. You could work around it by conditionally extending your ViewContainer to have a default constructor (init()), if the type is EmptyView. Then you can write

    var viewContainer2 = ViewContainer<EmptyView>()
But that's probably not what you want is it. Default generic arguments aren't implemented yet, see (https://stackoverflow.com/questions/42015081/can-i-assign-a-...). It would have possibly removed the <EmptyView> aspect. So you always have to give a type to ViewContainer, if you provide no way for the compiler to infer it.
Re:Static Types in SwiftUI by Razengan on Tuesday November 05, 2019 @06:37PM (#21458093)
> var viewContainer2 = ViewContainer<EmptyView>()

Yes, that would be a workaround for myself, but for a game engine's API, it'd be ugly to require users to write that every time. :)

And there are cases where they might not even know the type.

Re:Static Types in SwiftUI by DelightOne on Tuesday November 05, 2019 @06:46PM (#21458174)
It seems the compiler might be smarter than I thought he is (see a poster above), if so I learnt something new. :)

And it seems I didn't understand your problem, you wanting a variable that can change it's type instead of just some syntactic sugar, hmm.