TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

SwifData and List with children

Forums > SwiftUI

@amuu  

I am having problem loading swiftData model items in List

here is my 2 model

@Model
final class Category: Identifiable,Hashable {
    @Attribute(.unique) var uniqueID: String
    var name: String
    var iconName: String

    var subCategories : [Subcategory]? = []

    init(name: String, iconName: String) {
        self.uniqueID = UUID().uuidString
        self.name = name
        self.iconName = iconName
    }

    func hash(into hasher: inout Hasher) {
        hasher.combine(uniqueID)
    }
}

@Model
final class Subcategory: Identifiable,Hashable {
    @Attribute(.unique) var uniqueID: String
    @Relationship(inverse: \Category.subCategories) var category: Category
    var name: String
    var iconName: String

    init(category: Category, name: String, iconName: String) {
        self.category = category
        self.uniqueID = UUID().uuidString
        self.name = name
        self.iconName = iconName
    }

    func hash(into hasher: inout Hasher) {
        hasher.combine(uniqueID)
    }

}

This is how i am creating my List

  List {
      OutlineGroup(viewModel.categories, children: \.subCategories) { category in
          CategoryCell(category: category)
      }
  }

I have double checked the sub categories are coming with the FetchRequest but give me Failed to produce diagnostic for expression; please submit a bug report error when I try to create list

2      

Hacking with Swift is sponsored by String Catalog.

SPONSORED Get accurate app localizations in minutes using AI. Choose your languages & receive translations for 40+ markets!

Localize My App

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.