Post

Replies

Boosts

Views

Activity

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
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 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
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. 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 SwiftData #Predicate cannot test for nil relationship
Based on my testing if you define inverse relationship then nil comparison works on Xcode Version 15.0 (15A240d)
Replies
Boosts
Views
Activity
Sep ’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.
Replies
Boosts
Views
Activity
Sep ’23
Reply to #Predicate doesn't work with enum
I forgot to add the code for App, any help on this would be much appreciated. SwiftDataEnumDemoApp import SwiftUI import SwiftData @main struct SwiftDataEnumDemoApp: App { var body: some Scene { WindowGroup { ContentView() .modelContainer(for: Car.self) } } }
Replies
Boosts
Views
Activity
Sep ’23
Reply to Error saving @Model with enum
@alexanderwe Has anyone tried using enum inside the Query predicate? For me enum gets saved however doesn't work with Query Refer https://developer.apple.com/forums/thread/737929
Replies
Boosts
Views
Activity
Sep ’23
Reply to How to reorder list items with Swift Data?
Can you provide a minimum reproducible code so that others can help
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Sep ’23
Reply to Issue with SwiftData on macOS app
Can you try quitting Xcode, clearing DerivedData and trying again?
Topic: App & System Services SubTopic: Core OS Tags:
Replies
Boosts
Views
Activity
Sep ’23
Reply to Issue with SwiftData on macOS app
When I click the add button I get the message printed item save sucessfully. I have tested your code on macOS Sonoma release candidate (macOS 14.0 (23A339)) with Xcode Version 15.0 (15A240d)
Topic: App & System Services SubTopic: Core OS Tags:
Replies
Boosts
Views
Activity
Sep ’23
Reply to Is it safe to mark SwiftData (@Model) classes as Sendable?
If possible also add the tag Swift, IMHO it might help to ask in swift.org (https://forums.swift.org/c/swift-users/15) and please cross link this post.
Replies
Boosts
Views
Activity
Aug ’23
Reply to SwiftData. Predicate. Issue accessing self (Entity) inside a Predicate
I feel even #Predicate<Entry>{$0.item == name} should work, give it a try without storing it in a variable.
Replies
Boosts
Views
Activity
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:
Replies
Boosts
Views
Activity
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:
Replies
Boosts
Views
Activity
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:
Replies
Boosts
Views
Activity
Aug ’23
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 } ....
Replies
Boosts
Views
Activity
Aug ’23
Reply to Swift compiler crashes with simple SwiftData model
Try removing didSet and try it Try removing private set One way to isolate the problem is to keep commenting out and simplifying your model till it no longer crashes and then you can isolate the problem. Then file a feedback with the isolated problem.
Replies
Boosts
Views
Activity
Aug ’23
Reply to SwiftUI - scrollTo Animation Disappears
Not sure this helps, on iOS 17 there is an API called scrollPosition which is an alternate to ScrollViewReader Refer: https://developer.apple.com/wwdc23/10159
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Aug ’23