0 Replies
      Latest reply on Feb 27, 2020 4:17 AM by SN81
      SN81 Level 1 Level 1 (0 points)

        Hi guys,

        Yesterday during a work meeting a coworker said to use a struct as a view model instead of a class that derives from observable object so that you can avoid using all the property wrappers. While this approach technically works I don't feel it's the proper way to do things for a few reasons:

        1. It seems "anit-pattern". Not on part of Apple documetnation I've found uses a struct instead of an observabled object.

        2. It seems really memory inefficient. Imagine if the struct held large amounts of data, you'd be recreating it every time the view refreshed.

        3. The property wrappers do things under the hood (mainly create subscribers from what I'm seeing in the docs).

        Can someone with more knowlege of SwiftUI bring some clarity to this for me? Is ObservableObject or just a Struct more efficient?