WWDC22 SALE: Save 50% on all my Swift books and bundles! >>

SOLVED: UltimatePortfolio App: First steps in UI: FetchRequest in View

Forums > Articles

Dear all,

I have an app architecture related question.

According to MVVM design, a View should not directly access the Model. Only via a ViewModel access to the model should be possible.

In the UltimatePortfolio App, fetchRequest in the view is used to access objects in CoreData. So in my understanding, a view is accessing the model directly, either with the property wrapper @FetchRequest or via the initializer. Also, it creates a tight coupling between the view and CoreData, which may not be preferred.

Would that design choice not be in contrast to the MVVM design?

See also: Fetching objects from CoreData in SwiftUI

Maybe I'm getting something wrong or missed something (maybe the UltimatePortfolio App is not aiming for a MVVM design or similar, or the mentioned approach is indeed in accordance with MVVM design).

Any help is greatly appreciated.





I don't believe there was mention that the Ultimate Portfolio app was specifically aiming to conform to the MVVM architecture paradigm.


@cgaafary Thank you for the quick response and the clarification!

In case someone has a good resource which covers MVVM and core data (other than the one I already provided in my original post), I'd greatly appreciate it.


Hacking with Swift is sponsored by Emerge

SPONSORED Why are Swift reference types bad for app startup time, and what’s the performance cost of protocol conformances? That’s just a couple of the topics you can learn about on the Emerge blog — written by the app performance experts behind Emerge’s advanced app optimization and monitoring tools, based on their experience of working at companies like Apple, Airbnb, Snap, and Spotify.

Find out more

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.