Actually, I think it can be as simple as the following example
@Model
final public class MainItem {
var title: String?
@Relationship(deleteRule: .cascade)
var childs: [ChildItem]?
init(title: String? = nil, childs: [ChildItem]? = []) {
self.title = title
self.childs = childs
}
}
And the child item is.
@Model
final public class ChildItem {
var timestamp: Date?
// Add inverse as a simple variable
var item: MainItem?
init(timestamp: Date? = nil, item: MainItem? = nil) {
self.timestamp = timestamp
self.item = item
}
}
In the init of the MainItem, set the childs to 'childs: [ChildItem]? = [].' Do NOT set it to nil or you'll crash. I did.
Well, my code is crashing with the following error.
SwiftData/BackingData.swift:367: Fatal error: Unknown related type - ChildItem
My MainItem @Relationship
@Relationship(deleteRule: .cascade, originalName: "events", inverse: \ChildItem.item) var items: [ChildItem]?
My ChildItem
var item: MainItem?
It also crashes when using @Relationship var item: MainItem? for the ChildItem.
Are there any Apple engineers out there that have seen this thread? Several of us filed a Feedback about this. I was just wondering if this is being brought to Apple's attention or whether we are whistling in the wind.
Data is Codeable, but Data is not JSON. Again, one can code Data into JSON, but the Data is not JSON. So, the error message is bogus. I hope this issue has come to the attention of the Apple Developers.
Run your app in the Development environment. Then go into the CloudKit Dashboard, switch to Development environment and look for your new attribute there. Then if all is well, deploy it to the Production environment.
It's a file you add from Xcode. New / File / iOS / Resource / App Privacy. After that, you add to it like the below image. I'm using Xcode 15 beta 5 to do this. It's not available with current, non-beta version of Xcode.
My app uses a CloudKit public database and a private database. The image data in the public database is saved as a CKAsset and the data from the downloaded asset is saved in SwiftData. That data is not JSON data. Again, this works well until beta 5.
Actually, I think it can be as simple as the following example
@Model
final public class MainItem {
var title: String?
@Relationship(deleteRule: .cascade)
var childs: [ChildItem]?
init(title: String? = nil, childs: [ChildItem]? = []) {
self.title = title
self.childs = childs
}
}
And the child item is.
@Model
final public class ChildItem {
var timestamp: Date?
// Add inverse as a simple variable
var item: MainItem?
init(timestamp: Date? = nil, item: MainItem? = nil) {
self.timestamp = timestamp
self.item = item
}
}
In the init of the MainItem, set the childs to 'childs: [ChildItem]? = [].' Do NOT set it to nil or you'll crash. I did.
Well, my code is crashing with the following error.
SwiftData/BackingData.swift:367: Fatal error: Unknown related type - ChildItem
My MainItem @Relationship
@Relationship(deleteRule: .cascade, originalName: "events", inverse: \ChildItem.item) var items: [ChildItem]?
My ChildItem
var item: MainItem?
It also crashes when using @Relationship var item: MainItem? for the ChildItem.
Are there any Apple engineers out there that have seen this thread? Several of us filed a Feedback about this. I was just wondering if this is being brought to Apple's attention or whether we are whistling in the wind.
Data is Codeable, but Data is not JSON. Again, one can code Data into JSON, but the Data is not JSON. So, the error message is bogus. I hope this issue has come to the attention of the Apple Developers.
Run your app in the Development environment. Then go into the CloudKit Dashboard, switch to Development environment and look for your new attribute there. Then if all is well, deploy it to the Production environment.
It's a file you add from Xcode. New / File / iOS / Resource / App Privacy. After that, you add to it like the below image. I'm using Xcode 15 beta 5 to do this. It's not available with current, non-beta version of Xcode.
My app uses a CloudKit public database and a private database. The image data in the public database is saved as a CKAsset and the data from the downloaded asset is saved in SwiftData. That data is not JSON data. Again, this works well until beta 5.