Class inheritance with @Observable

Hi there!

I'm quite new to SwiftUI; just wanted to know if there any chance to get observation for values in a class that inherits from another class, with the @Observable macro.

I have the following class:

@Observable 
class SourceData {
    var sourceHorizontalResolution: Int?
    var sourceVerticalResolution: Int?
}

This class is declared as @State in ContentView, and passed to views using .environment():

struct ContentView: View {
    @State private var sourceData = SourceData()

     var body: some View {
        HStack {
            VStack {
                SourceView()
                    .environment(sourceData)
    //....More code 
}

Finally, I have this class, that would inherit from SourceData:

@Observable
class PreviewData: SourceData {
    
    override init() {
        super.init()
    }
    
    var placeholderText: NSImage? {...}
    
    var previewImage: NSImage? {
        guard let sourceHorizontalResolution = sourceHorizontalResolution, let sourceVerticalResolution = sourceVerticalResolution else { return placeholderText }
        // More code here...
        return image
    }

How can I observe for changes that occurs in SourceData, in my PreviewData class?

Class inheritance with @Observable
 
 
Q