I'm not coming in with a solution, but just to say that I'm seeing the exact same error. SwiftData unfortunately seems to be very poorly rolled out so far, even for a beta.
Editing to add: it seems as if I'm only getting those errors on attributes marked with the @Relationship marker.
Post
Replies
Boosts
Views
Activity
I've now found a (hopefully temporary) solution.
I added the following methods to each of my @Model classes:
func getValue<T>(for key: KeyPath<YourClassName, T>) -> T {
return self[keyPath: key]
}
func setValue<T>(for key: ReferenceWritableKeyPath<YourClassName, T>, to newValue: T) {
self[keyPath: key] = newValue
}
and those errors went away. But, of course, a litany of new ones arose, so hopefully yours goes better.
While I finally got it working with this, the litany of ensuing errors resolved, each one of these setters and getters is causing runtime crashes.
I had the exact same thing happen, eventually just reached out to support and they helped manually get it set up.
I literally just had this happen and after trying all of the same things, as silly as it was, quitting Xcode, reopening, and cleaning again did the trick. I hope yours is as easy. Wishing you luck.
This seems to currently be an issue with swiftData. With that said, I wrote custom encoder/decoders for each Model, for the time being, which eliminated this error.
Encoder
func encode(to encoder: Encoder) throws {
enum CodingKeys: String, CodingKey {
case name
}
do {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(name, forKey: .name)
} catch {
print("Encoding error: \(error)")
}
}
Decoder
public required convenience init(from decoder: Decoder) {
enum CodingKeys: String, CodingKey {
name
}
do {
let container = try decoder.container(keyedBy: CodingKeys.self)
let name = try container.decode(String.self, forKey: .name)
self.init(name: name)
} catch {
fatalError()
}
}
Once those were in place, the errors went away. Additionally, it'd probably make sense to just have your class conform to Equatable and implement an == method:
static func ==(lhs: OnlyName, rhs: OnlyName) -> Bool {
return lhs.name == rhs.name
}
I should also clarify that the only dependencies I'm currently using are those recommended in the video, namely:
URLSessionTransport
OpenAPIGenerator Runtime
OpenAPIGenerator Plugin
so I suspect that one of the dependencies loaded by these are the culprit, but I can't tell which one or how I would fix that even if/when I do find it.
This seems to be a currently existing SwiftData bug as several of us are seeing the same thing. I know I am also getting the exact same issue and nothing seems to fix it. Hoping there is an update soon to fix this.
I am continuing to see this issue as well and have opened a new thread with some code samples and where it's crashing, so feel free to follow that one as well.
I have also seen in a few different places that TTS in particular is failing with the same error and I suspect they may be related, so linking a related TTS thread as well: https://developer.apple.com/forums/thread/732335
To use your custom font you attach this modifier:
.font(.custom("exactNameOfYourFont"))
Note that the name of the font may not match the name of the file.
I went from an app that was working in many respects to one that basically doesn't load at all with the new betas. This Xcode b5 and iOS 17b4 ain't it.
Same as @mroman_omega I was not previously experiencing this, but am now in Beta 6.
Update: I ended up opening a TSI with Apple for this. After a lot of back and forth, my focused problem app seems to be working on the latest betas (iOS 17b6, Xcode 15b6). I cannot test my full project due to other emergent breaking issues in the latest betas, but it does make me hopeful that this is resolved.
Have been having the exact same issue, but mine was building fine with 15.3, the update to 15.4 broke it. Came to the same conclusion that it was the .svg image causing it to crash but shocked at how specifically it is that it's an svg with gaussian blur (which mine also has). Kind of bummed and hope this is fixed soon since mine can't just be recreated, the whole point of the asset is that it's a 'glow' image, so the blur is necessary. At least now I know what it is and can continue developing.
Main model:
@Model
class ResidentInfo: Codable {
@Attribute(.unique)
var id: UUID
var status: Status = Status.incomplete
var date: Date = Date()
var completingStaffMember: StaffMember? = nil
@Attribute(.unique)
var residentNumber: Int? = nil
var personalInfo: PersonalInfo
var identifyingInformation: IdentifyingInformation
var presentingProblems: String
var emergencyNeeds: EmergencyNeeds
var medicalInfo: MedicalInfo
var riskAssessment: RiskAssessment
var psychAssessment: PsychAssessment
var legal: Legal
var homelessHistory: HomelessHistory
var employment: EmploymentDetails
var education: EducationDetails
var substanceUse: SubstanceUse
var sexualBehavior: SexualBehavior
var independenceAssessment: IndependentLivingAssessment
var consentForServices: ConsentForServices
var photoVideoRelease: PhotoVideoRelease
var suicideAssessment: SuicideAssessment
var healthAssessment: HealthAssessment
@Attribute(.externalStorage)
var profilePhoto: Data? = nil
var _updatedDate: Date
init() {
id = UUID()
personalInfo = PersonalInfo()
identifyingInformation = IdentifyingInformation()
presentingProblems = ""
emergencyNeeds = EmergencyNeeds()
medicalInfo = MedicalInfo()
riskAssessment = RiskAssessment()
psychAssessment = PsychAssessment()
legal = Legal()
homelessHistory = HomelessHistory()
employment = EmploymentDetails()
education = EducationDetails()
substanceUse = SubstanceUse()
sexualBehavior = SexualBehavior()
independenceAssessment = IndependentLivingAssessment()
consentForServices = ConsentForServices()
photoVideoRelease = PhotoVideoRelease()
suicideAssessment = SuicideAssessment()
healthAssessment = HealthAssessment()
_updatedDate = Date()
}
private enum CodingKeys: String, CodingKey {
case id = "_id"
case status, date, completingStaffMember, residentNumber, personalInfo, identifyingInformation, presentingProblems, emergencyNeeds, medicalInfo, riskAssessment, psychAssessment, legal, homelessHistory, employment, education, substanceUse, sexualBehavior, independenceAssessment, consentForServices, photoVideoRelease, suicideAssessment, healthAssessment, profilePhoto, _updatedDate
}
public required init(from decoder: Decoder) throws {
do {
let container = try decoder.container(keyedBy: CodingKeys.self)
id = try container.decode(UUID.self, forKey: .id)
status = try container.decode(Status.self, forKey: .status)
date = try container.decode(Date.self, forKey: .date)
completingStaffMember = try container.decodeIfPresent(StaffMember.self, forKey: .completingStaffMember)!
residentNumber = try container.decodeIfPresent(Int.self, forKey: .residentNumber)
personalInfo = try container.decode(PersonalInfo.self, forKey: .personalInfo)
identifyingInformation = try container.decode(IdentifyingInformation.self, forKey: .identifyingInformation)
presentingProblems = try container.decode(String.self, forKey: .presentingProblems)
emergencyNeeds = try container.decode(EmergencyNeeds.self, forKey: .emergencyNeeds)
medicalInfo = try container.decode(MedicalInfo.self, forKey: .medicalInfo)
riskAssessment = try container.decode(RiskAssessment.self, forKey: .riskAssessment)
psychAssessment = try container.decode(PsychAssessment.self, forKey: .psychAssessment)
legal = try container.decode(Legal.self, forKey: .legal)
homelessHistory = try container.decode(HomelessHistory.self, forKey: .homelessHistory)
employment = try container.decode(EmploymentDetails.self, forKey: .employment)
education = try container.decode(EducationDetails.self, forKey: .education)
substanceUse = try container.decode(SubstanceUse.self, forKey: .substanceUse)
sexualBehavior = try container.decode(SexualBehavior.self, forKey: .sexualBehavior)
independenceAssessment = try container.decode(IndependentLivingAssessment.self, forKey: .independenceAssessment)
consentForServices = try container.decode(ConsentForServices.self, forKey: .consentForServices)
photoVideoRelease = try container.decode(PhotoVideoRelease.self, forKey: .photoVideoRelease)
suicideAssessment = try container.decode(SuicideAssessment.self, forKey: .suicideAssessment)
healthAssessment = try container.decode(HealthAssessment.self, forKey: .healthAssessment)
profilePhoto = try container.decodeIfPresent(Data.self, forKey: .profilePhoto)
_updatedDate = try container.decode(Date.self, forKey: ._updatedDate)
} catch {
throw error
}
}
func encode(to encoder: Encoder) {
do {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(id, forKey: .id)
try container.encode(status, forKey: .status)
try container.encode(date, forKey: .date)
try container.encodeIfPresent(completingStaffMember, forKey: .completingStaffMember)
try container.encodeIfPresent(residentNumber, forKey: .residentNumber)
try container.encode(personalInfo, forKey: .personalInfo)
try container.encode(identifyingInformation, forKey: .identifyingInformation)
try container.encode(presentingProblems, forKey: .presentingProblems)
try container.encode(emergencyNeeds, forKey: .emergencyNeeds)
try container.encode(medicalInfo, forKey: .medicalInfo)
try container.encode(riskAssessment, forKey: .riskAssessment)
try container.encode(psychAssessment, forKey: .psychAssessment)
try container.encode(legal, forKey: .legal)
try container.encode(homelessHistory, forKey: .homelessHistory)
try container.encode(employment, forKey: .employment)
try container.encode(education, forKey: .education)
try container.encode(substanceUse, forKey: .substanceUse)
try container.encode(sexualBehavior, forKey: .sexualBehavior)
try container.encode(independenceAssessment, forKey: .independenceAssessment)
try container.encode(consentForServices, forKey: .consentForServices)
try container.encode(photoVideoRelease, forKey: .photoVideoRelease)
try container.encode(suicideAssessment, forKey: .suicideAssessment)
try container.encode(healthAssessment, forKey: .healthAssessment)
try container.encodeIfPresent(profilePhoto, forKey: .profilePhoto)
try container.encode(_updatedDate, forKey: ._updatedDate)
} catch {
fatalError()
}
}
There are a ton more structs, but I don't want to inundate this thread before necessary