ForEach
中的 Content
不应该符合 View
吗?
这里ForEach定义为
现在我真的确定它应该声明为:
struct ForEach<Data, ID, Content> where Data: RandomAccessCollection, ID: Hashable, Content: View
所以我继续搜索并发现了这个:
所以现在我的问题是:
泛型可以在管道中的其他地方定义吗?或者这是文档中的错误
最佳答案
这是一个扩展,它使通用 ForEach
is-a View
,内容作为 View
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
extension ForEach : View where Content : View {
/// The type of view representing the body of this view.
///
/// When you create a custom view, Swift infers this type from your
/// implementation of the required `body` property.
public typealias Body = Never
}
关于generics - ForEach 中的内容不应该符合 View 吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66690130/