Unable to infer complex closure return type with SwiftUI

后端 未结 5 1117
执念已碎
执念已碎 2020-12-17 09:35

Following part 3 of Apple\'s tutorial on SwiftUI, Handling User Input, I get this error:

Unable to infer complex closure return type; add explicit ty

5条回答
  •  猫巷女王i
    2020-12-17 10:13

    For people getting this error on SwiftUI and looking for a way to debug their view stack

    This error happens mainly when there is a compilation issue on one child View.

    1 - Make sure your parent view can support multiple subviews (VStack, ZStack) and you have less than 10 subviews. Sometime you may want to add a Group wrapper.

    2 - If this is not the problem, there is probably an issue with one subview. Try to isolate the one you suspect to have the issue. Usually I copy the subview into a property and a different error appears

    var debug: some View {
            MyViewWithError(property: self.property)
    }
    

    Most of the time you'll encounter this because you pass the property (self.property) instead of a binding (self.$property)

    Hope this can help some people

提交回复
热议问题