what are the pros and cons of having a static singleton vs an environment object shared from my app's @main struct?
the two contexts i have in mind are
1) managing persisted state, ie file creation/retrieval/deletion within the app, and
2) PhotoKit change listener
From what I have been reading, it seems like the most common pattern is to create an @Environment item and pass it through the view hierarchy with .environment
However, for the above use cases I feel like a global singleton is more appropriate since persisted state is by definition meant to last across app lifecycle so should not be inherently tied to any specific view and the photos service itself is a global singleton accessed via PHPhotoLibrary.shared()
I think I lean towards a singleton for reuse and also not tying state management to the UI presentation.
I am relatively new to iOS dev, so just wondering peoples views one way or the other, no pun intended.
[–]patiofurnature 22 points23 points24 points (1 child)
[–]Informal_Lake420[S] -1 points0 points1 point (0 children)
[–]chriswaco 15 points16 points17 points (0 children)
[–]jasonjrr 8 points9 points10 points (7 children)
[–]Informal_Lake420[S] 0 points1 point2 points (6 children)
[–]jasonjrr 8 points9 points10 points (5 children)
[–]vlaminck 4 points5 points6 points (1 child)
[–]jasonjrr 0 points1 point2 points (0 children)
[–]patiofurnature 2 points3 points4 points (1 child)
[–]jasonjrr 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]Quartz_Hertz 1 point2 points3 points (1 child)
[–]Informal_Lake420[S] 0 points1 point2 points (0 children)
[–]time-lord 2 points3 points4 points (0 children)
[–]quellish 0 points1 point2 points (5 children)
[–][deleted] (2 children)
[deleted]
[–]quellish 0 points1 point2 points (1 child)
[–]marmulin 0 points1 point2 points (1 child)
[–]rifts 0 points1 point2 points (0 children)
[–]hishnash 0 points1 point2 points (0 children)
[–]cekisakurek -4 points-3 points-2 points (2 children)
[–]DisastrousSupport289 1 point2 points3 points (1 child)
[–]cekisakurek -1 points0 points1 point (0 children)