@StateObject
versus @ObservedObject
?Suggested approach: I would recommend you start by making the similarities and differences clear, then sum up by answering the question directly. So, you would say that both of these property wrappers monitor an observable object for changes, and refresh SwiftUI views when changes happen. However, @StateObject
is used when you create an object for the first time and want to retain ownership of it, whereas @ObservedObject
is used in other places where you pass the object and does not retain ownership.
Estimated difficulty: Easy
See the full list of iOS interview questions
Link copied to your pasteboard.