TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

Initialize persistent data on first application run

Forums > SwiftUI

Hello folks

I am a swift newby who learns how to develop iOS apps.

At my application I have some data that need to initialized/generated. I will need to keep this data in the application storage. I want to do it in a correct, swiftui-idiomatic way.

So I have 2 questions here:

  1. What is the proper way to run a function once to generate application data? The data must be generated either at installation time or the very first time the app starts.

  2. What is the proper way to store a struct of size ~2K? The data is generated once and stays effectively constant. I've read about UserDefaults.standard and it seems json serialization/deserialization is one way to do the job. Are there more standard ways to handle the persistent data?


Hacking with Swift is sponsored by Superwall.

SPONSORED Superwall lets you build & test paywalls without shipping updates. Run experiments, offer sales, segment users, update locked features and more at the click of button. Best part? It's FREE for up to 250 conversions / mo and the Superwall team builds out 100% custom paywalls – free of charge.

Learn More

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

Unknown user

You are not logged in

Log in or create account

Link copied to your pasteboard.