I'm getting 2 errors when I try add cloudkit..
The first because a direct relationship does not exist and the second is a container issue ...
error: Store failed to load. <NSPersistentStoreDescription: 0x3009c0ae0> (type: SQLite, url: file:///var/mobile/Containers/Data/Application/D931D996-869F-4CED-842E-D1373B0DE090/Library/Application%20Support/default.store) with error = Error Domain=NSCocoaErrorDomain Code=134060 "A Core Data error occurred." UserInfo={NSLocalizedFailureReason=CloudKit integration requires that all relationships have an inverse, the following do not:
GroupData: task
GroupSortOrder: group
TaskData: groupSortOrders} with userInfo {
NSLocalizedFailureReason = "CloudKit integration requires that all relationships have an inverse, the following do not:\nGroupData: task\nGroupSortOrder: group\nTaskData: groupSortOrders";
}
SwiftData/PersistentModel.swift:327: Fatal error: Unable to find a container with entity GroupSortOrder
My classes are as follows:
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
}
}
Post
Replies
Boosts
Views
Activity
It looks as though was related to the class relationships - I still have some testing to do but I now don't have any errors so it's looking good ... for info this is my class setup which appears ok ->
import Foundation
import CloudKit
import SwiftData
@Model
class TaskData: Identifiable, Equatable {
var id: UUID = 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()
// Define an optional relationship to GroupData
var group: GroupData?
// Define an optional relationship to GroupSortOrder
var groupSortOrders: [GroupSortOrder]? // Optional array
init(id: UUID = UUID(), title: String = "No Title", isDone: Bool = false, isToday: Bool = false, creationDate: Date = Date(), doneDate: Date = Date(), todayDate: Date = Date(), group: GroupData? = nil, 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.group = group
self.groupSortOrders = groupSortOrders
}
static func == (lhs: TaskData, rhs: TaskData) -> Bool {
lhs.id == rhs.id
}
}
@Model
class GroupData: Identifiable {
var id: UUID = UUID()
var title: String = "No Title"
var icon: String = "No Icon"
var creationDate: Date = Date()
// Define an optional relationship to TaskData with an inverse relationship to `group`
@Relationship(inverse: \TaskData.group)
var tasks: [TaskData]? // Optional array
// Define an optional relationship to GroupSortOrder
var groupSortOrders: [GroupSortOrder]? // Optional array
init(id: UUID = UUID(), title: String = "No Title", icon: String = "No Icon", creationDate: Date = Date(), tasks: [TaskData]? = nil, groupSortOrders: [GroupSortOrder]? = nil) {
self.id = id
self.title = title
self.icon = icon
self.creationDate = creationDate
self.tasks = tasks
self.groupSortOrders = groupSortOrders
}
}
@Model
class GroupSortOrder: Identifiable {
var id: UUID = UUID()
var sortOrder: Int = 0
// Define an optional relationship to GroupData with an inverse relationship to `groupSortOrders`
@Relationship(inverse: \GroupData.groupSortOrders)
var group: GroupData?
// Define an optional relationship to TaskData with an inverse relationship to `groupSortOrders`
@Relationship(inverse: \TaskData.groupSortOrders)
var task: TaskData?
init(id: UUID = UUID(), group: GroupData? = nil, task: TaskData? = nil, sortOrder: Int = 0) {
self.id = id
self.group = group
self.task = task
self.sortOrder = sortOrder
}
}