Group Group Group Group Group Group Group Group Group

Your Second iOS and SwiftUI App · Adding to your Model |

This is a companion discussion topic for the original entry at

Hi Jessy, I just found a small bug, maybe related to Swift UI, after adding a task and dismiss the sheet, if I click again on the + button, nothing happens, the button is not clickable anymore, however if I make the list scroll then try again to click the + button, it works, the modal sheet is presented. I did not try on a real device, it could be also a simulator bug …


1 Like

Thanks! Someone spotted it on a later video, so I’m aware: Your Second iOS and SwiftUI App · Observable Objects |

I’m seeing it both on-device and off, with Xcode 11.1 and 11.2. No word from Apple yet.

I found a little more with this bug, on my device (iOS 13.1.3) the button does work, but only if you tap a few times, as if there is some delay in the main screen getting focus. Additionally to the Edit / Done button already mentioned, if you interact with the scrollview first it will also work.

Changing sheet to popover makes no different.

I also tried using a callback function and passing {self.modalIsPresented = false} as an alternative to the @Environment code, but this also has the same issue.

This code gives me error with following message:
“Cannot use mutating member on immutable value: ‘self’ is immutable”

The only way I know of that that would show up is if you tried to have TaskStore be a structure instead of a class. (See the end of Episode 2)

If that’s not it, upload your project and I’ll have a look!

Got it.
You are correct. i changed TaskStore to class and error has gone. Thanks.
Other solution is to write my own method in struct and mark as mutating, right?

No, that wouldn’t work because we’re already dealing with a mutable property. The issue comes down to trying to modify an immutable copy of a struct, which has no access to the scope of the original.

SwiftUI’s easiest solutions for this are found in State and Binding, but I haven’t found those to be usable for delivering bound values to modal views. ObservedObject and Environment are the next place to go. Let me know if you find out a way to create the final version of TaskList without reference types!