0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

SwiftDataのプロパティに"hash"という名前を使うとクラッシュする

Posted at

これが該当のコード

import Foundation
import SwiftData

@Model
final class HogeHoge {
    var hash: String?

    init(_hash: String?) {
        self.hash = hash
    }
}

以下がエラー箇所です。

{
    @storageRestrictions(accesses: _$backingData, initializes: _hash)
        init(initialValue) {
                    _$backingData.setValue(forKey: \.hash, to: initialValue)
                    _hash = _SwiftDataNoType()
        }

    get {
                    _$observationRegistrar.access(self, keyPath: \.hash) //ここ?
                    return self.getValue(forKey: \.hash)
        }

    set {
                    _$observationRegistrar.withMutation(of: self, keyPath: \.hash) {
                            self.setValue(forKey: \.hash, to: newValue)
                    }
        }
}

予約語かなんか使ってるんでしたっけ?とりあえずコンパイル時には警告がなくて、値を取得するときに初めてエラーになる感じでした。

0
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?