'ReSwift and State with a reference type property
Since ReSwift is based around immutability of State, the Swift struct is obvious choice to work with.
But what if I really need a reference type property in a State to have a hierarchy of items? Let's say, my Model is composed with trees, so a TreeNode has to have a reference type to store a weak reference to its parent TreeNode. What is the best approach with ReSwift in this case?
Should I make a TreeNode object immutable and allocate a new one if the State is changed? Or maybe it's best to compose a TreeNode abstraction as an array of array of TreeNode structs (but in this case I will constantly search through that array of arrays in order to find a parent).
There's not much information about ReSwift and the community is not large enough yet. So, maybe I can have some discussion here? Thanks!
Solution 1:[1]
I think indirect enums are your best bet: https://www.hackingwithswift.com/example-code/language/what-are-indirect-enums
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Francesco Puglisi |