View References

I need to edit an attribute of a core data entity fetched in a previous view. So I put var entityName: FetchedResults.Elementin the second view to get access to the entity. But when I do this it doesn't actually get the entity it gets a copy of the entity so when changes are made to it it doesn't actually change. Basically is there a way to pass a reference to an attribute of an object to a struct so that when you set that reference to a value the entity changes?

Any help would be greatly appreciated. All the best!

I haven’t done this in UIKit, but in SwiftUI I pass the entity to the second view, modify the attribute on that entity, then perform a Context save of the Entity (by using a function in my CodeData stack). CoreData entities are classes and therefore get passed by reference.

Having modified and saved the Entity + attribute, you then probably need to force a view refresh, which can be tricky depending on your implementation of CoreData in your views and whether UIKit or SwiftUI.

regards, Michaela

View References
 
 
Q