1

I have Company entity in Core Data that has relationship one-to-many Activities

I've added there derived property to Company

activities.@count

but then accessing in SwiftUI view this property gives me invalid result. It usually works ok but on logout/login where I think there is company update and relationship update it for the first time gives 0 count of activities in spite there are activities related to company

using this

self.user?.company?.activitiesCount ?? 0

gives 0

using this

self.user?.company?.activities.count ?? 0

gives 75

Michał Ziobro
  • 10,759
  • 11
  • 88
  • 143

1 Answers1

2

As per Apple documentation on Derived Attributes for Core Data

Data recomputes derived attributes when you save a context. A managed object’s property does not reflect unsaved changes until you save the context and refresh the object.

More info here: https://developer.apple.com/documentation/coredata/nsderivedattributedescription?language=swift

alpennec
  • 1,864
  • 3
  • 18
  • 25