SwiftUI中的'NavigationView'声明是如此混乱。(也许我不擅长Swift。)在声明中'NavigationView'是一个结构,但是初始化器甚至没有主体,就像协议声明一样
NavigationView声明如下:
@available(iOS 13.0, OSX 10.15, tvOS 13.0, *)
@available(watchOS, unavailable)
public struct NavigationView<Root> where Root : View {
public init(root: () -> Root)
public var body: _View { get }
/// 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
}
NavigationView declaration code
我复制了“ NavigationView”声明样式,编写了一些类似的代码,如下所示。
我的模仿代码如下:
@available(iOS 13.0, OSX 10.15, tvOS 13.0, *)
public struct MyNavigationView<Root> where Root:View {
public init(root: () -> Root)
public var body: _View { get }
public typealias Body
}
但是有一些错误,就像:
"initializer requires a body"
"Expected '{' to start getter definition"
"Expected '=' in type alias declaration"