import SwiftUI import Combine struct ContentView: View { @ObservedObject private var foo: Foo = .init() var body: some View { print("body") return Text("Hello, World!") } } final class Foo: ObservableObject { private let subject: CurrentValueSubject<Void, Never> = .init(()) var objectWillChange: AnyPublisher<Void, Never> { subject.eraseToAnyPublisher() } }
"body"
が無限に print
される。import SwiftUI import Combine struct ContentView: View { @ObservedObject private var foo: Foo = .init() var body: some View { print("body") return Text("Hello, World!") } } final class Foo: ObservableObject { private let subject: CurrentValueSubject<Void, Never> = .init(()) let objectWillChange: AnyPublisher<Void, Never> init() { objectWillChange = subject.eraseToAnyPublisher() } }