【发布时间】:2019-10-24 10:35:38
【问题描述】:
View 协议定义如下:
public protocol View : _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.
associatedtype Body : View
/// Declares the content and behavior of this view.
var body: Self.Body { get }
}
所以View现在是PATed协议,不能直接作为返回类型,虽然swift 5.1的不透明返回类型可以处理这个,但是为什么要声明associatedtype Body : View,而不是直接声明var body: View { get } ?
【问题讨论】: