Post

Replies

Boosts

Views

Activity

Help with 2 way relationships with classes (SwiftData / cloudkit)
Hi I’m having real problems trying to get a simple “to do” type app working with cloudkit. It works fine with SwiftData but as soon as I add CloudKit I get lots of “container not found errors “ which I think relates to the relationships between my classes. If I strip out the group sort order class it works fine. I’ve stripped the app back to basics to test - I want to be able to add a “task” (task data) to a “group list “ (group data) also also store the position of the task in that list (group sort order) as there may be lots of tasks in a list. The same task could also be in a different group list with a different position in the list (so another entry and value in group sort order) .. why does the following not work?? any help appreciated! //  TaskData.swift //  TaskOutApp // import Foundation import SwiftData `@Model class TaskData: Identifiable, Equatable { var id = UUID() var title: String = "No Title"     var isDone: Bool = false     var isToday: Bool = false     var creationDate: Date = Date()          var doneDate: Date = Date()     var todayDate: Date = Date()     // Use an array of GroupSortOrder to maintain both group and sort order     var groupSortOrders: [GroupSortOrder]? = nil          init(id: UUID = UUID(), title: String = "No Title", isDone: Bool = false, isToday: Bool = false, creationDate: Date = Date(), doneDate: Date = Date(), todayDate: Date = Date(), groupSortOrders: [GroupSortOrder]? = nil) {         self.id = id         self.title = title         self.isDone = isDone         self.isToday = isToday         self.creationDate = creationDate         self.doneDate = doneDate         self.todayDate = todayDate         self.groupSortOrders = groupSortOrders     }          static func currentDateString() -> String {         let formatter = DateFormatter()         formatter.dateStyle = .short         formatter.timeStyle = .short         return formatter.string(from: Date())     }          static func == (lhs: TaskData, rhs: TaskData) -> Bool {         lhs.id == rhs.id     } } @Model class GroupData: Identifiable {     var id = UUID()     var title: String = "no title"     var icon: String = "no icon"     var creationDate: Date = Date()     var task: [TaskData]? = []          init(id: UUID = UUID(), title: String, icon: String, creationDate: Date = Date(), task: [TaskData] = []) {         self.id = id         self.title = title         self.icon = icon         self.creationDate = creationDate         self.task = task     }          static func currentDateString() -> String {         let formatter = DateFormatter()         formatter.dateStyle = .short         formatter.timeStyle = .short         return formatter.string(from: Date())     } } @Model class GroupSortOrder: Identifiable {     var id = UUID()     var group: GroupData? = nil     var sortOrder: Int = 0          init(id: UUID = UUID(), group: GroupData? = nil, sortOrder: Int = 0) {         self.id = id         self.group = group         self.sortOrder = sortOrder     } }`
3
0
358
Sep ’24