I have a code that needs to be ran about every year to update some files at the app launch and I'm trying to come up with the best way to do that. What I need to be able to basically force the app to run the code whenever I need to update the files.
This is what I came up with that I think would work but I'm not sure if that's the best way.
Are there any other options to handle this type of logic?
App version 1 - INITIAL RELASE.
This code would work as long as I don't add an update.
// First launch
@main
struct SwifUIPlayGroundApp: App {
@AppStorage("shouldLoad") var shouldLoad = true
init(){
if shouldLoad{
print("Loading...")
shouldLoad = false
}else{
print("No need to relaod...")
}
}
}
App version 2 - UPDATE 1.
Here I would need to add a second variable to force the update shouldUpdate
. I would also need to change the logic to check for the shouldUpdate
instead of the shouldLoad
and set the shouldLoad
to true
to be prepared for future updates.
// UPDATE 1
@main
struct SwifUIPlayGroundApp: App {
@AppStorage("shouldUpdate") var shouldUpdate = true // new
@AppStorage("shouldLoad") var shouldLoad = true
init(){
if shouldUpdate{
print("Loading...")
shouldUpdate = false
shouldLoad = true // prepare for next update
}else{
print("No need to relaod...")
}
}
}
App version 3 - UPDATE 2.
Here I would need to change the logic back to check for the shouldLoad
instead of the shouldUpdate
and set the shouldUpdate
to true
to be prepared for future updates.
// UPDATE 2
@main
struct SwifUIPlayGroundApp: App {
@AppStorage("shouldUpdate") var shouldUpdate = true
@AppStorage("shouldLoad") var shouldLoad = true
init(){
if shouldLoad{
print("Loading...")
shouldUpdate = true // prepare for next update
shouldLoad = false
}else{
print("No need to relaod...")
}
}
}
App version 4 - UPDATE 3.
Repeat what I did in UPDATE 1...