Well, I resolved it not long after posting. I had to make PostContainer a struct and update the containers themselves using the index. See example below.
if var index = self.containers.firstIndex(where: {$0.subreddit == subreddit}) {
// Update previous container
self.containers[index].timestamp = Date()
self.containers[index].posts = posts
self.containers[index].active = true
print("Updated old container")
} else {
// Create the container
// Set to active, because its a new query
let container = PostContainer(timestamp: Date(), subreddit: subreddit, posts: posts, type: .search, active: true)
self.containers.append(container)
print("Created new search container")
}
I guess because with structs, you're creating a new version of the object when it's updated and @Published is able to see the change. With class, it seems to struggle to know if there's been a change or not.
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: