VStack 中包含超过 10 个元素。怎么没有出现错误

问题描述 投票:0回答:1

我的代码如下。

import SwiftUI

struct ContentView: View {
    var body: some View {
        
        VStack {
            Text("Line 0")
            Text("Line 1")
            Text("Line 2")
            Text("Line 3")
            Text("Line 4")
            Text("Line 5")
            Text("Line 6")
            Text("Line 7")
            Text("Line 8")
            Text("Line 9")
            
            Text("Line 10")
            Text("Line 11")
            Text("Line 12")
            Text("Line 13")
            Text("Line 14")
            Text("Line 15")
            Text("Line 16")
            Text("Line 17")
            Text("Line 18")
            Text("Line 19")
            
            Text("Line 20")
            Text("Line 21")
            Text("Line 22")
            Text("Line 23")
            Text("Line 24")
            Text("Line 25")
            Text("Line 26")
            Text("Line 27")
            Text("Line 28")
            Text("Line 29")
        
        }
    }
}

#Preview {
    ContentView()
}

据我所知,它可以接受作为参数的视图数量是有限的。 VStack 最多可以容纳 10 个视图,因此引入了

Group

但是我没有收到任何错误并且预览工作正常。甚至应用程序也运行良好。

为什么错误

ambiguous reference to member 'buildBlock()’.
没有出现?

swiftui ambiguous
1个回答
0
投票

ViewBuilder.buildBlock
现在采用类型参数包(在 Swift 5.9 中引入),而不是 11 个单独的重载,每个重载具有不同数量的类型参数。

static func buildBlock<each Content>(_ content: repeat each Content) 
    -> TupleView<(repeat each Content)> where repeat each Content : View

因此不再对观看次数进行硬编码限制。我认为唯一的限制是 Swift 进行类型检查需要多长时间。

© www.soinside.com 2019 - 2024. All rights reserved.