【发布时间】:2019-11-17 02:58:37
【问题描述】:
是否可以从 SwiftUI 中的 Button 继承?我厌倦了它,每次都会出错,因为 Button 期待某种通用参数。
import SwiftUI
struct ButtonSubClass: Button<Label: View> {
var body: some View {
Text("Hello, World!")
}
}
XCode 会自动添加 <Label: View> 部分,但我不知道这意味着什么,或者我实际上需要在大括号中添加什么。
我试过Button<View>,但后来我收到错误Protocol type 'View' cannot conform to 'View' because only concrete types can conform to protocols
【问题讨论】:
-
你打算做什么?