我在SwiftUI视图主体中看到了这样的代码,用于初始化和放置视图:
MyView<Spacer>("xyz",
image: "myimage",
color: .orange,
binding: self.$demoBinding
)
字符串
我想知道泛型<Spacer>
在这里的用途是什么,语法规则说了什么?
下面是MyView
的声明和初始化器:
typealias Action = () -> Void
struct MyView<Content: View>: View {
private var text, hint: String
private var image: String?
private var color: Color?
private var content: Content?
private var onClick: Action?
private var useToggle: Bool
@Binding private var toggleState: Bool
init(_ text: String, hint: String = "", image: String? = nil, color: Color? = nil, binding: Binding<Bool>) {
}
型
}
1条答案
按热度按时间5m1hhzi41#
第一个月
很可能是这样开始的
字符串
然后在属性中使用
Something
。型
SwiftUI最常见的用法是传递“Content”
型
我建议您查看Swift协议部分,以便了解更多有关该主题的信息
https://docs.swift.org/swift-book/documentation/the-swift-programming-language/protocols/