Generics in custom component – unable to access enum-specific property

I’m creating a custom component: a list of cards.

Intended appearance:

enter image description here

This component accepts an array of generic type [T] and creates a card for each item in the array.

In this instance, I’m passing it an array of [PlantStage], which is an enum that represents various stages of gardening. Each stage has its own definition.

enum PlantStage: String, CaseIterable {
    case seed = "Seed"
    case germination = "Germination"
    case seedling = "Seedling"
    case bulb = "Bulb"
    case leafyGrowth = "Leafy Growth"
    case flowering = "Flowering"
    case pollination = "Pollination"
    case fruitFormation = "Fruit Formation"
    case vegetableFormation = "Vegetable Formation"
    case harvested = "Harvested"
    
    var definition: String {
        switch self {
        case .seed: "A small object from which a new plant can grow."
        case .germination: "The emergence of a tiny root and shoot."
        case .seedling: "A young plant with its first set of leaves."
        case .bulb: "An underground bulb from which a new plant can grow."
        case .leafyGrowth: "The growth of leaves, stems, and roots establishing the plant."
        case .flowering: "A stage where the plant produces flowers."
        case .pollination: "A period of pollen transfer leading to plant fertilization."
        case .fruitFormation: "The development of edible fruits."
        case .vegetableFormation: "The development of edible greens."
        case .harvested: "The act of gathering mature plants."
        }
    }
}

The problem is I can’t access definition. The cards end up looking like this:

enter image description here

My component code:

struct CardSelectionList<T>: View where T: RawRepresentable, T.RawValue == String {
    
    let items: [T]

    let newlySelectedPillText: String
    let currentlyActivePillText: String
    
    @Binding var selectedItem: T
    @Binding var selectedIndex: Int
    
    var body: some View {
        ScrollView {
            VStack(alignment: .leading, spacing: 10) {
                ForEach(0..<items.count, id: .self) { i in
                    CardSelectable(
                        title: items[i].rawValue,
                        description: items[i].definition ?? nil,
                        currentlyActivePillText: currentlyActivePillText,
                        isNewlySelected: i == selectedIndex,
                        newlySelectedPillText: newlySelectedPillText
                    )
                    .onTapGesture {
                        selectedIndex = i
                        selectedItem = items[i]
                    }
                }
            }
        }
    }
}

#Preview {
    CardSelectionList(
        items: PlantStage.allCases,
        newlySelectedPillText: "New Stage",
        currentlyActivePillText: "Current Stage",
        selectedItem: .constant(.seed),
        selectedIndex: .constant(0)
    )
}

I’m guessing because this component accepts an array of any type, not all types will have an associated definition. I tried addressing this by making card descriptions optional, but in this case it should have one.

I don’t understand why items[i].definition doesn’t return the definition when items[i] is of type PlantStage and all plant stages have an associated definition.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật