I have been building a SwiftUI/SwiftData app for some time that has been working fine in both the simulator and devices I have loaded from Xcode. These include two iPhones an iPad and a VisionPro.
I have gotten to the point where I wanted to do some external beta testing so uploaded the App to the AppStore and then had a couple of users download via TestFlight. Unfortunately the App crashes and I have been unable to figure out why based on the feedback that I have gotten.
The app has 4 Models that are linked in a fairly straightforward manner. There is a Habit class that is the central object. An Aspiration class that may have several Habits associated with it. An Anchor Class and a Celebration Class both attach to a Habit.
I was able to get my neighbor to use TestFlight to download the App and it crashed when trying to insert a Habit but Aspirations, Anchors and Celebrations work fine and can be added, stored and deleted without issue.
I then had my neighbor connect their phone to my computer and I download the app directly and it works fine as expected even when not connected to the debugger so clearly something is different between the two environments and I am at a loss so could use someone with good knowledge to help me figure this out.
Well no thanks to Apple or anyone on here I did finally figure out what was causing the crash. It was something I had heard in passing in some Youtube video on SwiftData (I've watched so many I can't remember exactly where) I picked it up but it could well have been either Paul Hudson or Stewart Lynch said something about SwiftData not liking optionals in predicates.
Well it turns out that I was using a title of an optional object (although the way the app is implemented this Optional is really optional) in a sortDescriptor and this is what was causing the issue.
The super frustrating thing is it worked fine in both the simulator and locally downloaded from Xcode builds with not even a hint of a problem so the fact that it only showed up months into development when I finally decided to start external testing was unfortunate since by then the app was way more complicated and the errors reported via TestFlight were cryptic (Swifthdata Getter Exception?)
How is that supposed to help one figure out what is going wrong. Also after months of wrestling this this I finally tried reaching out to Apple Developer Support and that was a black hole. NOT IMPRESSED!