By the way. The following also works.
data.variable?.contains(SomeString) ?? false
But the following items do not work even though you won't get a warning or an error.
data.variable!.starts(with: SomeString)
data.variable!.contains(SomeString)
Post
Replies
Boosts
Views
Activity
I actually have found a workaround. Here it is.
let predicate = #Predicate<Data> { data in
data.result == result
&& data.variable?.starts(with: SomeString) ?? false
}
Note the data.variable?. and the ?? false. This works. I still don't think I should have to discover these things. Something needs to be fixed on Apple's end.
Has SwiftData been implemented on visionOS yet? I hasn't been. I don't know about beta 6.
I thought I had a fix, but I do not have a fix.
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.
Looks like this has been fixed with Xcode 15 beta 6. Yay!
They changed the ModelConfiguration inits with Xcode 15 Beta 5. Perhaps that is the issue you are seeing.
Can you check FB12749735?
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.
May I see your initializer?
Right! Just adding the attribute isn’t enough. You need to save data for the attribute. Please mark my response with the green acceptance.
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.