Post

Replies

Boosts

Views

Activity

Reply to What would be the best logic for updating a file periodically after an app has been released
You could use a stored lastUpdated date and compare it on each launch: @main struct SwifUIPlayGroundApp: App {     @AppStorage("lastUpdated") var lastUpdated = Date()     private var shouldUpdate: Bool {         let now = Date()         let hoursInYear = 8760         guard let hoursPassed = Calendar.current.dateComponents([.hour], from: lastUpdated, to: now).hour else { return false }         return hoursPassed >= hoursInYear     }     init() {         if shouldUpdate {             lastUpdated = Date() // Set it to now             print("Loading...")         } else {             print("No need to relaod...")         }     } }
Jan ’23