Предполагаемый внешний вид:

Этот компонент принимает массив универсального типа [T] и создает карточку для каждого элемента в массив.
В данном случае я передаю ему массив [PlantStage], который представляет собой перечисление, представляющее различные этапы садоводства. У каждого этапа свое определение.
Код: Выделить всё
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."
}
}
}

Код моего компонента:
Код: Выделить всё
struct CardSelectionList: 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..
Подробнее здесь: [url]https://stackoverflow.com/questions/78421509/generics-in-custom-component-unable-to-access-enum-specific-property[/url]