I have a List
where I would like to put at least eleven Section
views.
It seems SwiftUI was only designed for ten subviews because there is an "extra argument in call" error when I try to do this. How do you workaround this language design flaw, supposing your hands were tied so that you could not use a better technology like UIKit or React Native JSX?
protocol SectionKind: CaseIterable, CustomStringConvertible where AllCases == [Self] {
static var description: String { get }
var rawValue: String { get }
}
extension SectionKind {
static func makeSection() -> some View {
Section(header: Text(Self.description)) {
ForEach(Self.allCases, id: \.rawValue) { asana in
TitleView(title: asana.rawValue.capitalized, subtitle: asana.description.capitalized, action: nil)
}
}
}
}
enum Section1: String, SectionKind {
static let description = "one"
case a
case b
var description: String {
switch self {
case .a: return "alpha"
case .b: return "bravo"
}
}
}
enum Section2: String, SectionKind {
static let description = "two"
case c
case d
var description: String {
switch self {
case .c: return "charlie"
case .d: return "delta"
}
}
}
enum Section3: String, SectionKind {
static let description = "three"
case e
case f
var description: String {
switch self {
case .e: return "echo"
case .f: return "foxtrot"
}
}
}
enum Section4: String, SectionKind {
static let description = "four"
case g
case h
var description: String {
switch self {
case .g: return "golf"
case .h: return "hotel"
}
}
}
enum Section5: String, SectionKind {
static let description = "five"
case i
case j
var description: String {
switch self {
case .i: return "india"
case .j: return "juliett"
}
}
}
enum Section6: String, SectionKind {
static let description = "six"
case k
case l
var description: String {
switch self {
case .k: return "kilo"
case .l: return "lima"
}
}
}
enum Section7: String, SectionKind {
static let description = "seven"
case m
case n
var description: String {
switch self {
case .m: return "mike"
case .n: return "november"
}
}
}
enum Section8: String, SectionKind {
static let description = "eight"
case o
case p
var description: String {
switch self {
case .o: return "oscar"
case .p: return "papa"
}
}
}
enum Section9: String, SectionKind {
static let description = "nine"
case q
case r
var description: String {
switch self {
case .q: return "quebec"
case .r: return "romeo"
}
}
}
enum Section10: String, SectionKind {
static let description = "ten"
case s
case t
var description: String {
switch self {
case .s: return "sierra"
case .t: return "tango"
}
}
}
enum Section11: String, SectionKind {
static let description = "eleven"
case u
case v
var description: String {
switch self {
case .u: return "uniform"
case .v: return "victor"
}
}
}
struct AlphabetView: View {
var body: some View {
NavigationView {
Section1.makeSection()
Section2.makeSection()
Section3.makeSection()
Section4.makeSection()
Section5.makeSection()
Section6.makeSection()
Section7.makeSection()
Section8.makeSection()
Section9.makeSection()
Section10.makeSection()
Section11.makeSection() // Extra argument in call
}
}
}