News for hackers. Stuff that matters.
Re:Static Types in SwiftUI by DelightOne on Tuesday November 05, 2019 @06:21PM (#21457944)
His problem might be that certain features (of SwiftUI) you cannot hook yourself (your own implementation) into (since they are based on protocols which cannot be implemented yourself since they are not public and so not meant to be implemented by yourself), which makes it, at times, necessary to use workarounds to public-facing apis.

Or it might be something else.

Re:Static Types in SwiftUI by Razengan on Tuesday November 05, 2019 @06:44PM (#21458154)
You're correct, part of the problem is indeed that, though I'm not completely sure myself.

But how do things like EmptyView work? How do they conform to the View protocol without having a body property (that must also be a View)?

Re:Static Types in SwiftUI by DelightOne on Tuesday November 05, 2019 @06:58PM (#21458286)
I think it has a body type [0] (Never). And since a default implementation is provided [1] the compiler probably does not complain. This default body implementation does likely not draw anything, but that's just guessing.

[0]: https://developer.apple.com/documentation/swiftui/emptyview/... [1]: https://developer.apple.com/documentation/swiftui/view/32785...

Re:Static Types in SwiftUI by favorited on Tuesday November 05, 2019 @07:03PM (#21458328)
It's because of Body's type:

    public struct EmptyView: View {
        @inlinable public init()
        public typealias Body = Never
    }
Because Body is Never, you can't access EmptyView's body property.
Re:Static Types in SwiftUI by Razengan on Tuesday November 05, 2019 @07:50PM (#21458652)
Re:Static Types in SwiftUI by favorited on Tuesday November 05, 2019 @08:25PM (#21458852)
I don't see why not. When I trick it into calling `body` on an EmptyView, I get this runtime failure:

> Thread 1: Fatal error: body() should not be called on EmptyView.

So I don't think the implementation is doing anything beyond the fatalError() call from that forum thread. At least not at this point in time.