What is the ObservableObject Protocol in Swift’s Combine?
Allow your object to self-monitor its properties
Published in
2 min readJun 14, 2020
Conforming to the ObservableObject
protocol provides a handy way to monitor when one of its @Published
properties change. However, we can’t know which exact property has changed. It is created to help you when using SwiftUI in your projects.
Without a further ado, let’s explore the ObservableObject
protocol in practice.
Let’s Start
Say we have a simple class called ObjectToBeObserved
:
What if we want to be notified when its value property is changed? We can conform to the ObservableObject
and mark the value
property with a Published
property wrapper: