Xcode 12.3 | SwiftUI 2.0 | macOS 11
I'm trying to get a custom initializer to write this:
Section("TITLE") { ... content ... }
Instead of this:
Section(header: Text("TITLE") { ... content ... }
But I cannot create a custom initializer because self.initis not recognized:
extension Section {
init(_ title: String, @escaping () -> Content) {
self.init(........ <--- No autocompletions for self initializers
}
}
I have the same problem with custom inits for Buttons.
Does anyone knows how to access to that initializers from extensions?
Here is a solution (tested with 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With