Skip to content

Instantly share code, notes, and snippets.

@marty-suzuki
Created March 18, 2021 14:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marty-suzuki/1cae05fe677f4956ffb31cf7f7ff3364 to your computer and use it in GitHub Desktop.
Save marty-suzuki/1cae05fe677f4956ffb31cf7f7ff3364 to your computer and use it in GitHub Desktop.
import Combine
import SwiftUI
struct ContentView: View {
@ObservedObject var viewModel = ViewModel()
var body: some View {
Button("Refresh") { viewModel.objectWillChange.send() }
ScrollView(.vertical) {
LazyVStack {
ForEach(1...100000, id: \.self) {
Tester($0)
}
}
}
}
final class ViewModel: ObservableObject {
let objectWillChange = ObservableObjectPublisher()
}
}
struct Tester: View {
private let object: Object
init(_ value: Int) {
self.object = Object(value)
}
var body: some View {
Text("Row \(object.value)")
}
private final class Object {
let value: Int
deinit {
print("deinit value = \(value)")
}
init(_ value: Int) {
self.value = value
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment