gpt4 book ai didi

swift - SwiftUI 中的自定义部分初始值设定项

转载 作者:行者123 更新时间:2023-12-05 03:46:05 27 4
gpt4 key购买 nike

Xcode 12.3 | SwiftUI 2.0 | macOS 11

我正在尝试获取自定义初始化程序来编写此代码:

Section("TITLE") { ... content ... }

取而代之的是:

Section(header: Text("TITLE") { ... content ... } 

但我无法创建自定义初始化程序,因为无法识别 self.init:

extension Section { 
init(_ title: String, @escaping () -> Content) {
self.init(........ <--- No autocompletions for self initializers
}
}

我对按钮的自定义初始化有同样的问题。

有谁知道如何从扩展中访问初始化器?

最佳答案

这是一个解决方案(使用 Xcode 12.1/iOS 14.1 测试)

extension Section where Parent == Text, Content: View, Footer == EmptyView {
init(_ title: String, content: @escaping () -> Content) {
self.init(header: Text(title), content: content)
}
}

On GitHub

关于swift - SwiftUI 中的自定义部分初始值设定项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65480256/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com