|
The @Published property observer didSet in the code below will not trigger when the var courses, an array, has all objects removed (.removeAll) or has a object added (.append). It will trigger if the array is replaced (array = array1). I don't understand why? Any insights for me? Thanks.
With lines 65-69 didSet triggers, without and with comment slashes removed, didSet doesn't trigger. |
|
I think this is just an unfortunate side effect of property wrappers. Internally, Since you're using Combine, you should be able to convert the operations in the property observer into a subscriber:
|
|
Thank you @bbatsell. Your subscriber solution solved my problem. I have to admit I am not entirely clear on why I need to go that route or how it solves the problem - so I am now in research mode! |
|
I admittedly didn’t do a great job explaining. Let me give it another try. When you use any property wrapper (of which
But your property observer When you create What’s confusing about it is that Swift abstracts out a lot of what’s happening, so it appears that you are still operating on just an The reason that the subscription works is that the whole purpose of the |
|
Very much appreciate your further explanation @bbatsell. It makes sense to me now. I am not a "real" developer but a retired EE doing development as a hobby so I run into issues like this alot and appreciate when folks like you are willing to take the time to help. Thanks. Jim |
|
Thanks for the explanation. I was having this issue with the iExpense project. I found that if you want to trigger didSet after making an append or remove operation on an array you can just add one line setting the array equal to itself. No need to create extra temp variables. For example:
or
|
|
|
|
Thanks for the full explanation. I hope to have Xcode 11.5 soon. In the mean time, I have used the simple solution of @ryanlintott. |
|
@twostraws, im experiencing this in xcode12 beta. i wonder if there has been a regression? |
SPONSORED Transform your career with the iOS Lead Essentials. Unlock over 40 hours of expert training, mentorship, and community support to secure your place among the best devs. Click for early access to this limited offer and a FREE crash course.
Sponsor Hacking with Swift and reach the world's largest Swift community!
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.
Link copied to your pasteboard.