Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented 'OnAppFirstRun' View Modifier #22

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ricky-stone
Copy link
Contributor

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.

Copy link
Contributor Author

@ricky-stone ricky-stone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@SwiftfulThinking
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants