I am trying to use a custom Copy-on-write type with SwiftUI. I have found that it takes the expensive path every time in the below code. Any thoughts about how I can avoid the copy and deinit for every drag event? Thanks for any insights or hints you might have.
swift
struct CowType {
init() {
self.detail = Detail(values: [])
}
private var detail: Detail
var values: [Int] { detail.values }
mutating func appendValue(_ value: Int) {
if !isKnownUniquelyReferenced(&detail) {
print("performing expensive copy")
detail = Detail(values: values)
}
detail.values.append(value)
}
private final class Detail {
init(values: [Int]) {
self.values = values
}
deinit {
print("calling deinit")
}
var values: [Int]
}
}
struct ContentView: View {
@State var state = CowType()
var body: some View {
Text("Hello, world! \(state.values.count)")
.padding()
.gesture(DragGesture().onChanged { _ in
state.appendValue(Int.random(in: 1...100))
})
}
}
Post
Replies
Boosts
Views
Activity
Under preferences :: components there is usually a long list of simulators that you can install. I am not seeing any of them (empty). Is there a trick to downloading old simulators?
I am trying to track down a regression between iOS 14.3 and iOS 14.4.
Trying to track it down but it seems like there is a regression in TIFF metadata handling in iOS 14.4.