SwiftfulUI icon indicating copy to clipboard operation
SwiftfulUI copied to clipboard

Implemented 'OnAppFirstRun' View Modifier

Open ricky-stone opened this issue 1 year ago • 1 comments

Designed for initial app setup tasks, this modifier ensures code execution only on the app's first launch. It's ideal for one-time configurations.

ricky-stone avatar Nov 17 '23 03:11 ricky-stone

I improved the code by adding FirstRunManager, a singleton, to manage one-time execution logic. This ensures that certain actions only run on the first app launch. We use a singleton for centralized state management, making the code more robust and preventing multiple executions, even across different views. The struct OnAppFirstRunModifier leverages this singleton to decide whether to execute its action, enhancing code reusability and clarity.

I think you misunderstood what I was referring to. This Singleton isn't adding any functionality from the original, I don't think?

With this modifier, the dev could add

HomeView()
     .onAppFirstRun{
     }
SecondView()
     .onAppFirstRun{
     }

... and many more times. Since it's a ViewModifer, it can be added to infinite amount of views. However, only the very first modifier will execute the action, which would seem like a bug to the developer.

SwiftfulThinking avatar Nov 17 '23 14:11 SwiftfulThinking