Avatar
最小(?)構成できた。 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() } }
2:37 AM
"body" が無限に print される。
2:43 AM
↓だと起こらない・・・。 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() } }