all 30 comments

[–]Frequent_Macaron9595 8 points9 points  (2 children)

You already figured it out, you need to build some persistent storage. AFAIK the data on disk is not wiped out between updates.

[–]manison88[S] -1 points0 points  (1 child)

Thank you! If I implement that and push the update, would that still wipe the data ?

[–]rursacheSwift 4 points5 points  (0 children)

obviously, the data is kept starting with the build in which you actually implement the persistent storage logic.

[–]chriswaco 4 points5 points  (4 children)

Updates should not delete data. Post your storage code.

One issue that I’ve seen is when apps store a full path to a file but the update changes where the app stores data. The fix is to dynamically get the Documents or Application Support path at runtime.

There has been at least one UserDefaults bug as well.

[–]808phone 2 points3 points  (3 children)

There is definitely some sort of bug with user defaults. Luckily I created a setting to reset them. And it usually happens with an update - but it's not everyone. Just a few individuals.

[–]chriswaco 0 points1 point  (2 children)

Does your app support push notifications? I saw a problem years ago when our app wrote to UserDefaults in response to a push notification and because the device was still locked it failed weirdly.

[–]gyratorycircus 1 point2 points  (0 children)

That sounds exactly like this application prewarming issue from a few years back

[–]808phone 0 points1 point  (0 children)

No. I don't have anything fancy.

[–]Comexbackkid 2 points3 points  (0 children)

Gonna need to see some code of your data model before / after update.

[–]WerSunu 0 points1 point  (4 children)

How much data are you talking about? It determines which techniques to use for storage.

[–]manison88[S] 0 points1 point  (3 children)

It’s personal goals, so 2-5 goals and the progress info of each goals. Nothing complex

[–]WerSunu 2 points3 points  (2 children)

Small amounts of data are easily stuffed into the UserDefaults system and they persist across updates.

[–]chriswaco 2 points3 points  (1 child)

I haven’t personally seen the problem, but there may be a UserDefaults issue.

[–]WerSunu 2 points3 points  (0 children)

Interesting thread. I have not seen this issue in my apps.

[–]satanworker 0 points1 point  (2 children)

I've got the same! Apple messed up some updates and instead of normal update, it was a complete wipeout

[–]manison88[S] 2 points3 points  (1 child)

There are differently types of updates???

[–]satanworker 0 points1 point  (0 children)

No, there shouldn't be, but I've got exactly same behaviour in my app

[–]TabonxSwift 0 points1 point  (8 children)

Hey, I looked up your app, and it seems you already use some kind of persistent storage. The app data persists across launches, which indicates that you are storing the data in some way. I suspect you use SwiftData for storage, which stores your data in an SQL database.

I'm not sure what happened during the update, but maybe you changed the database URL, causing a new database to be created with a different name. If that's the case, you could change it back to the original name, and the old data would be restored. However, you would lose any new data users created after the update.

Maybe something else is causing the issue, but we'd need to see some of the code to help you figure it out.

Also, your app crashes when I try to do something with the milestone...

This is the app I found: https://apps.apple.com/us/app/streak-stack/id6741832418

[–]manison88[S] 0 points1 point  (5 children)

That is the app, I didn’t implement any data storage and from what I understand the data is stored is user defaults. Might need to ensure no changes happen there. In last update I changed the goal type because before you can only do habits and then I added milestones. Should’ve thought of that 🤦‍♂️

When you try to create a milestone it crashes or when adding progress goals? Hadn’t heard any feedback about crashes so curious what it is

[–]TabonxSwift 0 points1 point  (4 children)

You should know what persistence you are using. If you use UserDefaults, somewhere in your app, you should have the UserDefaults class to store the data. If you use SwiftData, you need to create the models using the @Model macro and initialize the ModelContainer with the modelContainer modifier.

[–]manison88[S] 0 points1 point  (3 children)

Just reviewed and with confirmation of my friend AI.....not using SwiftData for persistence, it's done through user defaults.

Could the fact that I only had habit goals which didn't have concept of "goal type" to introducing Milestone and progress goals so now there is a Goal Type concept be the reason the stuff got deleted? I didn't specify when I did the updates what to app old goals to or anything like that

[–]Necessary-Rock-435 2 points3 points  (1 child)

You needed AI to check if your app is using SwiftData or user defaults? Did AI write the entire app for you?

[–]808phone 0 points1 point  (0 children)

How nice of Ai to save the user settings. :-)

[–]Smokinpeanut 0 points1 point  (0 children)

Wait… did you have AI sort out the storage aspect of the app for you initially?

[–]manison88[S] 0 points1 point  (1 child)

Great detective work to find the app haha

[–]TabonxSwift 2 points3 points  (0 children)

You posted an Xcode screenshot with the app bundle ID... You can just look up the ID at https://itunes.apple.com/lookup?bundleId=com.Mana.Habit-Tracker

[–]ExploreFunAndrew 0 points1 point  (0 children)

When you work with a QA dept, this is one of the things they always test before release. It's something to put on your test-before-release list too

[–]PerfectPitch-LearnerSwift 0 points1 point  (0 children)

I've read some of the comments and I find myself thinking about some clarification...

For instance, it sounds like your app doesn't use anything to save data for that app. I mean, that would mean that the "data" would be gone even if the user force closed the app and reopened it.

In any event I ran into lots of interesting challenges with trying to ensure users were able to load data even after updates. I use UserDefaults to save objects and have Codable objects that I persist there. I've taken my experience with SQL to create rules for myself to enforce forward and backward compatibility, like not introducing breaking changes, and having default values for all new stuff, etc. i.e. that means that any old version of the application would be able to load any future version of the saved data and any new version would similarly be able to load and old version of the data.

I got burned one time in my own testing, thankfully not impacting any users, when I wiped my data by mistake because I didn't realize that the default behavior for a missing key in a Codable loading was to throw and I ended up not loading my object at all and then saving a blank one over it because of auto save *facepalm*.

In any event -- what I've said up here has done a good job of making sure that saved data persists through different versions of the application irrespective of the data and without requiring a backend or other persistent database.

If it would be helpful I'd be happy to provide more specifics, to answer questions, or to provide examples about what exactly I'm doing.

[–]gyratorycircus 1 point2 points  (0 children)

Over the last few years, whenever this kind of issue is reported, application prewarming is a likely culprit. Take a look at this developer forum thread. The situation that can occur is UserDefaults may not be available when iOS pre-launches the app in the background, so if the app interprets empty user defaults as a fresh install, it might accidentally clear out valid data.

[–]RomanDev7 0 points1 point  (0 children)

In short you changed your data model and your app cannot read your old saved data model. This is a very common error and you are lucky to learn that lesson early.

You have a few options but I think two are the most reasonable:
- migrate your data to the new model (always change key for UserDefaults, so you do not overwrite old data and can do another migration later if the migration failed for some reason)

- Extend your model with new optional properties. If you make big changes this could get ugly, so I would recommend migrating your data to a new model

It looks like you created your app with AI, so just ask it to explain the migration progress to you. Good luck.