GO FURTHER, FASTER: Try the Swift Career Accelerator today! >>

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?

2      

Hacking with Swift is sponsored by try! Swift Tokyo.

SPONSORED Ready to dive into the world of Swift? try! Swift Tokyo is the premier iOS developer conference will be happened in April 9th-11th, where you can learn from industry experts, connect with fellow developers, and explore the latest in Swift and iOS development. Don’t miss out on this opportunity to level up your skills and be part of the Swift community!

Get your ticket here

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

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

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.