NEW: Learn to build amazing SwiftUI apps for macOS with my new book! >>

Me or a SwiftUI bug? Probably me, but...

Forums > 100 Days of SwiftUI

Hello all,

I finished Day 60 yesterday, described here:

What I'm more interested in is why, as demonstrated in the brief example app that I wrote, the List view shown in this video, updates only when button 2 is pressed:

Shouldn't button 1, which changes state in a published property on an observable object, also trigger SwiftUI to update the UI?

Here is the super brief example code:

For whatever reason, only button 2 (which adds and then removes an element from the array the List is tied to) causes SwiftUI to update the user interface.

This seems wrong to me, but on the other hand, perhaps I am missing something.

Any thoughts would be greatly appreciated.

Thanks and take care,



Hi Russ

I think it because when you push Button 1, the List is not changed (only the item inside the List) therefore the View is not redrawed, however when you remove and then add it back the List has changed and then the View is redrawed.

I maybe wrong.



Hi Nigel,

Thanks for your reply. It's curious – I need to play with this a bit more.

I'm wondering if both buttons would cause the list to update if Item were a struct and not a class – a value type then, rather than a reference type.

This came up in an extension that I made for Day 60 on the Friends app – I was downloading random placeholder user images and found that the images didn't update in the list for the first few users.

However, now that I'm using Core Data after Day 61, the issue is moot. It seems that SwiftUI picks up changes to the managed objects from Core Data, even though I'm loading the avatar images after the managed objects were themselves created (essentially changing an instance of a class, just like the example app that I made).

Take care,



Hacking with Swift is sponsored by RevenueCat

SPONSORED Spend less time managing in-app purchase infrastructure so you can focus on building your app. RevenueCat gives everything you need to easily implement, manage, and analyze in-app purchases and subscriptions without managing servers or writing backend code.

Get Started

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

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.

Unknown user

You are not logged in

Log in or create account

Link copied to your pasteboard.