2

I was trying to set a class to be a persistent data source using @Model annotation, and somehow this happened:

enter image description here

The code above is generated by the compiler and the error is located in it.

Here is my code:

import SwiftData

class Animal {
}

@Model
class Dog: Animal {
    let breed: String
    init(breed: String) {
        self.breed = breed
    }
}

However, when I declare the Dog class with no super class, it work as expected.

Any idea?

  • 2
    Don't use inheritance together with SwiftData, that's my recommendation. Maybe it will work later but right now the Model macro doesn't support it. – Joakim Danielson Aug 10 '23 at 14:46
  • I was trying to use SwiftData in my project, and the same error occurred when I tried to apply the `@Model` annotation to a class that inherits from `NSObject`. Turns out the issue is related to a model with inheritance. – catmotionmachine Aug 10 '23 at 15:12

0 Answers0