【发布时间】:2020-01-18 15:51:14
【问题描述】:
有人能解释一下some View 应该如何使用吗?
将类型转换为所需类型只是将创建的变量提供给另一个方法/初始化器的适当算法,我说得对吗?
在下面的代码中,只有 force-cast 帮助我创建了一个 TupleView。
let shadowRectangle: some View = self.shadowRectangle(
width: w,
heightTop: heightTop
)
return AnyView(
ZStack<TupleView<(Rectangle, Path)>>.init(content: { () -> TupleView<(Rectangle, Path)> in
return TupleView<(Rectangle, Path)>.init((shadowRectangle as! Rectangle,
simplePathView as! Path))
})
View 的很多方法返回some View 看起来很奇怪。每次我想在当前范围之外使用它时,我都应该强制转换它。比如.offset()方法返回some View。
【问题讨论】:
标签: swift swiftui swift-protocols