Post

Replies

Boosts

Views

Activity

Reply to SwiftData: Accessing collection from computed property forces dependency update ?!? and this compute property and so on... cycle
workaround @Model final class Item { var name: String var id: UUID @Relationship(deleteRule:.cascade, inverse: \Entry.item) var entries: [Entry] init(name: String) { self.name = name self.id = UUID() entries = [] } } extension Item { private var _entries: [Entry]? { return try? self.context?.fetch(FetchDescriptor<Entry>(predicate:#Predicate<Entry>{ $0.item.id == id},sortBy: [SortDescriptor(\Entry.date, order: .forward)])) } } extension Item { func checkingDate()->Date?{ let _ = _entries //... return Date() } } But is really awkward not allowed directly to access the collection property inside one entity...
Aug ’23