Skip to main content
Post Reopened by JeremyP swift
edited tags
Link
Joakim Danielson
  • 53k
  • 5
  • 35
  • 78
Post Closed as "Duplicate" by Cristik swift
Source Link
Michael May
  • 372
  • 2
  • 18

SwiftData: Return from initializer without initializing all stored properties

everyone. I encountered the error message in the title of this post thrown by Xcode 15.0.1 for the following code which uses SwiftData with SwiftUI:

import SwiftUI
import SwiftData

@Model
final class PorcelineTile {
    @Attribute (.unique) var name: String
    var additionalInfo: String
    var pattern: [String: Double]

    init(name: String, pattern: [String: Double] = ["":0.0], additionalInfo: String = "") {
        self.name = name
        self.additionalInfo = additionalInfo
        self.pattern = pattern
    }

    @Relationship(deleteRule: .cascade) var items: [Item]
}

I have tried commenting out any one or two of the three properties and their corresponding mappings in the initialiser but the error message just wouldn't go away. I'm really puzzled what could've gone wrong. Thanks a lot for your help!