Created
March 18, 2021 14:37
-
-
Save marty-suzuki/1cae05fe677f4956ffb31cf7f7ff3364 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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