|
I banged my head for a day trying to figure out why my didSet property observer was not firing. After I could not figure it out I loaded up my code for iExpense for 100 Days of Swift UI. It wasn't firing there either. Then I loaded Paul's version of iExpense. It also didn't work. I then booted off a Mojave boot drive and everything works as it should. Then I did some searching and found this discussion: https://forums.swift.org/t/swift-5-2-struct-property-wrapper-didset-defect/34403 Does anyone have any insight into this? -Sean |
|
You might want to take a look at - SOLVED: Triggering didSet of a PropertyObserver confusion - on this forum a couple days ago. |
|
Thanks. I am not sure how I missed that other post because I was looking for this topic before posting my own. However, that post apparently solves the problem by usine Combine. That does not change the fact that functionality that used to work prior to Swift 5.2 no longer works. I was working on the 100 days of SwiftUI day 77 challenge and coulnd't get my didSet code to work. That is when I went back to the iExpense app in project 7 to try to figure out what I was doing wrong and found it no longer worked either. Anyone following the project 7 lesson will not be able to get their code to work right now and they will have no idea why. |
|
This appears to be a regression bug in Swift 5.2, but can be worked around. The iExpense code includes the following action in reponse to the 'Save' button of the Add Expense view (your variable names might vary):
The trouble seems to be that the .append() operation does not trigger the property's didSet. But an assignment will, so can rewrite the second line above:
Presumably this will be fixed in the next Swift/Xcode. Unless anyone can explain why this would be intended behaviour? |
|
.... or after appending the new items you can just say
That creates a new version of itself and triggers didSet. |
|
I'm confused. I just checked the project in both Xcode 11.4 and 11.4.1 and I can't reproduce the bug. IIUC adding an item shouldn't work in 11.4 which uses Swift 5.2, that's it? I guess it wasn't the bug, since it works for me in both. |
|
I have fixed the bug and pulled the fix into 5.2. It will be available in the next Xcode 11.4 release. |
|
|
|
SAVE 50% All our books and bundles are half price for Black Friday, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.
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.