Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
83 views
in Technique[技术] by (71.8m points)

SwiftUI and Core Data - Workflow

currently I'm looking into using Core Data within my SwiftUI project and I'm facing some architecture questions.

Since touching some SwiftUI projects, I learned quite a few things that where managed using the @State and @Binding principle where it wasn't an issue to pass a parent state to a child view. Now by incorporating Core Data into my project I wonder how the appropriate way would look like to access data in child views, I guess passing an NSManagedObject as a @Binding is not the way it should be done...

So, my current situation looks like this:

  • ContentView that loads those NSManagedObjects and displays it as a list with NavigationLink views
  • by clicking on a list row item, the user gets navigated to the corresponding child view showing those list item in detail
  • within this child view the selected list item should be displayed with it's information that should be able to alter

I think the following intention is fitting better, but there also some open points I'm thinking about. Within the ContentView all NSManagedObject relevant data gets loaded and displayed as list. By clicking on an list item, the child view appears and the only thing I pass is the specific id of that list item. Within the child view by using this id I'll load the data and display it, ready to alter. Maybe incorporating MVVM at this stage also makes sense.

What do you think about that solution, is that to intended way for those situations?

Another question I have, when using MVVM, how to decide what to put within a single ViewModel? Is it a good starting point to put every use case of the app into it's own ViewModel?

Many thanks in advice!

question from:https://stackoverflow.com/questions/65540624/swiftui-and-core-data-workflow

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...