We switched ObjectCaptureSession
to use the new Observation (https://developer.apple.com/videos/play/wwdc2023/10149/) feature. Unfortunately, the sample code update was not released at the same time as the API change and we apologize for the inconvenience this caused. The new sample code that switches to the new Observation feature is available now.
As noted, ObjectCaptureSession
no longer uses the Combine ObservableObject
which means all SwiftUI usage points no longer need @ObservedObject
(as the WWDC session above describes). We highly recommend storing the session in a ground truth model class for maximal control of its lifecycle and passing it by reference as needed to SwiftUI views. As the Observation session points out, this change should simplify usage and allow SwiftUI better efficiency in updates. We encourage you to watch the WWDC session on Observation to learn more about the benefits of switching to Observation in your own code.
As part of this change, the implicit Combine publishers for $state
and $feedback
(and others) that were previously automatically created by conforming to ObservableObject
also went away when we dropped this conformance. To replace this functionality, we introduced the new AsyncSequence
based ObjectCaptureSession.Updates<T>
properties to support apps that want to handle programmatic state updates, like our sample app. Async update loop code can be placed programmatically in Task
s within your app, or attached to .task()
view modifiers right in your SwiftUI code to tie their lifecycle to a particular View
.