Post

Replies

Boosts

Views

Activity

Reply to SwiftData Predicate Issue
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.
Aug ’23
Reply to SwiftData and 'Circular references'
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.
Aug ’23
Reply to SwiftData and 'Circular references'
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.
Aug ’23
Reply to Does SwiftData support UIImage
Here's how I turned my data into a UIImage. var myImage: UIImage? = nil if let imageData = modelEntity.imageData { myImage = UIImage(data: imageData) }
Replies
Boosts
Views
Activity
Aug ’23
Reply to Swift compiler crashes with simple SwiftData model
I don't see '@Model' above the class definition. @Model public final class Note: Identifiable {...
Replies
Boosts
Views
Activity
Aug ’23
Reply to SwiftData Predicate Issue Workaround
It looks like the following works as well. data.variable?.starts(with: SomeString) == true data.variable?.contains(SomeString) == true
Replies
Boosts
Views
Activity
Aug ’23
Reply to How to form a search predicate using swift data with a one to many model
Here's the fix that I found. let searchPredicate = #Predicate<SectionsSD> { $0.toArticles?.contains(filter) ?? false }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Aug ’23
Reply to SwiftData Predicate Issue Workaround
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)
Replies
Boosts
Views
Activity
Aug ’23
Reply to SwiftData Predicate Issue
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.
Replies
Boosts
Views
Activity
Aug ’23
Reply to visionOS and SwiftData: 'member' macro cannot be attached to property
Has SwiftData been implemented on visionOS yet? I hasn't been. I don't know about beta 6.
Replies
Boosts
Views
Activity
Aug ’23
Reply to SwiftData Predicate Issue
I thought I had a fix, but I do not have a fix.
Replies
Boosts
Views
Activity
Aug ’23
Reply to SwiftData and 'Circular references'
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.
Replies
Boosts
Views
Activity
Aug ’23
Reply to SwiftData and 'Circular references'
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.
Replies
Boosts
Views
Activity
Aug ’23
Reply to Xcode Version 15.0 beta 5 (15A5209g), SwiftData Problem - "The given data was not valid JSON."
Looks like this has been fixed with Xcode 15 beta 6. Yay!
Replies
Boosts
Views
Activity
Aug ’23
Reply to SwiftData AppGroups
They changed the ModelConfiguration inits with Xcode 15 Beta 5. Perhaps that is the issue you are seeing.
Replies
Boosts
Views
Activity
Aug ’23
Reply to Feedback Assistant - Lack of Responses
Can you check FB12749735?
Replies
Boosts
Views
Activity
Aug ’23
Reply to Xcode Version 15.0 beta 5 (15A5209g), SwiftData Problem - "The given data was not valid JSON."
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.
Replies
Boosts
Views
Activity
Aug ’23
Reply to Xcode Version 15.0 beta 5 (15A5209g), SwiftData Problem - "The given data was not valid JSON."
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.
Replies
Boosts
Views
Activity
Aug ’23