Post

Replies

Boosts

Views

Activity

Reply to @Model and Encodable cause the error Ambiguous use of 'setValue(for:to:)'
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.
Jun ’23
Reply to Can't test equality of two model entities with a predicate
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 }
Jun ’23
Reply to SwiftData model in Swift package
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
Jun ’23
Reply to XCode 15.3 Command CompileAssetCatalog failed with a nonzero exit code
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.
Apr ’24
Reply to CoreData: error: Row (pk = 1) for entity 'ResidentInfo' is missing mandatory text data for property 'name'
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() } }
Apr ’24