Post

Replies

Boosts

Views

Activity

Reply to Copy-on-write types and SwiftUI
As @OOPer indicated, using an object is a way around the problem: I needed to use this to avoid the expensive copies. swift final class Container: ObservableObject { private var cow = CowType() var values: [Int] { cow.values } func append(_ value: Int) { objectWillChange.send() cow.append(value) } } Interestingly, @Published runs into the same problem as @State, making a copy at every iteration. e.g., swift final class Container: ObservableObject {   @Published var cow = CowType() } This makes cow make a copy every time it is mutated.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Mar ’21
Reply to Copy-on-write types and SwiftUI
UPDATE: On the second inspection, making CowType Equatable does not fix the issue. On the Swift.org forum, Jonathan Hise Kaldma thought that making CowType Equatable might solve the problem. It was a good thought, but didn't work out in this case.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Mar ’21