0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【SwiftData】ビルドしたらモデルファイルの中で@storageRestrictionsエラーが発生した

Posted at

概要

  • SwiftDataコンパイル時にこの画面でエラーが発生した。
  • おそらく何かしらのコードがSwiftDataの求める構造体の定義に合致していないから

発生したエラー

 @storageRestrictions(accesses: _$backingData, initializes: _priority)
    init(initialValue) {
        _$backingData.setValue(forKey: \.priority, to: initialValue)
        _priority = _SwiftDataNoType()
    }
    get {
        _$observationRegistrar.access(self, keyPath: \.priority)
        return self.getValue(forKey: \.priority)
    }
    set {
        _$observationRegistrar.withMutation(of: self, keyPath: \.priority) {
            self.setValue(forKey: \.priority, to: newValue)
        }
    }

解決策

  • enumInt, Codableに準拠させた
- enum Priority: Int, Codable {
+ enum Priority: Int, Codable {
-   case low
-   case medium
-   case height
+   case low = 0
+   case medium = 1
+   case height = 2
}
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?