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.
Mar ’21