UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

Change value of an object in one-to-many - Core Data

Forums > SwiftUI

Hi everyone! I was follow this tutorial https://www.hackingwithswift.com/books/ios-swiftui/one-to-many-relationships-with-core-data-swiftui-and-fetchrequest

And I have a question, how can I change the value of an object in this one-to-many scenario? Let's say that, in Paul's example, I want to update the name of some of the candy:

let candy1 = Candy(context: moc)
candy1.name = "Mars"
candy1.origin = Country(context: moc)
candy1.origin?.shortName = "UK"
candy1.origin?.fullName = "United Kingdom"

For example, Mars to any other name. Is there a way to do that?

2      

@Bnerd  

You mean in the example above or in the future dynamically?

2      

I mean, once the object is already created and in the future I want to change a value (for example, the name)

2      

BUILD THE ULTIMATE PORTFOLIO APP Most Swift tutorials help you solve one specific problem, but in my Ultimate Portfolio App series I show you how to get all the best practices into a single app: architecture, testing, performance, accessibility, localization, project organization, and so much more, all while building a SwiftUI app that works on iOS, macOS and watchOS.

Get it on Hacking with Swift+

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

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

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.