SwiftUI & Core Data - Tying it all together

Bryan San Andres continued his previous SwiftUI & Core Data discussion.

Today’s example covered creating a MovieReview application. During the demo we discussed creating a new DataModel which contained a Movie Entity, making sure to apply the appropriate names and data types.

We discussed PreviewProviders which allows you to preview screens while developing. DataController handled the connection with CoreData connections: App → Controller → DataModel. The data controller inherits from ObservableObject (ability to see changes automatically that happen in DB).

Next, we discussed List View and setting up an environment with an additional ManagedObjectContext variable. We utilized fetch requests to set up predicates or sort descriptors (talked about on previous knowledge exchange). Bryan taught us how to edit the body of a page. We defined as NavigationView which allowed us to have a View Stack (VStack). We defined a tool bar where we had the ability to add a a movie, which contained a button, a title, and an image which toggles the 'State' defined by a boolean variable. We discussed Sheets which are equivalent to popups.

Finally, Bryan covered the Screen View, which was where we had the ability to edit/create a Movie record. New syntax we learned for the screen view provided the ability to Save Movie through ManagedObjectContext. Try? allows the ability to call a function that normally would need a catch but with this syntax would not. We discussed how to add input fields, as well as pickers.

Previous
Previous

OutSystems Reactive DataGrid

Next
Next

Codewars Problem Review