Post

Replies

Boosts

Views

Activity

Reply to SwiftData. Predicate. Issue accessing self (Entity) inside a Predicate
Based on my experience, using self inside #predicate is not allowed. Do you have unique identifier field for Item? If so store that then use unique identifier in a variable and then use id inside your #predicate. Assume name is the unique identifier then use the following code example: let id = self.name let predicate = #predicate { $0.item.name == id } ....
Aug ’23
Reply to iOS 17b6: Simultaneous accesses to ..., but modification requires exclusive access crash using Observation and SwiftUI
Just curious: Why do you need a shared static property on AppModel? Since Folder conforms to identifiable in SidebarView could you just use ForEach(folders) { folder in? Note: I don't have an iOS 17 device so couldn't test it on real device. Could you make the above 2 changes mentioned and test it? Just trying to understand what causes the crash?
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Aug ’23
Reply to SwiftData crashes the app on iOS Beta 6
I have created a default SwiftData app by selecting the storage as SwiftData. The app runs fine on iOS simulator, there is no crash. I am using Xcode 15 Beta 6. Do you have any framework that you have added to your project? Can you clear DerivedData and create a new project and test using Xcode Beta 6?
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Aug ’23
Reply to iOS 17b6: Simultaneous accesses to ..., but modification requires exclusive access crash using Observation and SwiftUI
Given below is my understanding (I could be wrong). It looks like a concurrency issue. @Observable does ensure properties are accessed on the main thread, so it is thread safe. However by accessing a static property containing the AppModel, the AppModel might not longer guarantee thread safety. Based on the crash it seems like it is caused by simultaneous access (possibly from different threads). Debug Turn on Swift Strict Concurrency to complete to spot any warnings thrown by the compiler. Solution If you want to pass around the model use @Environment across views and access them across views If you have different models and need to talk to each other find ways to isolate and protect access using actors.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Aug ’23
Reply to SwiftData @Query crashes when trying to filter or sort using an enum or relationship
Yes I am also facing the same issue, problem is there seems to be no way to compare enum, comparing enum always fails and comparing using rawValue crashes. Could you file a feedback, hopefully it gets fixed. https://developer.apple.com/documentation/swiftdata/preservingyourappsmodeldataacrosslaunches# claims that enum is supported however I am not sure how to get it to work.
Sep ’23