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

A way to restore a previously selected theme. #3

Open
multinerd opened this issue Aug 10, 2017 · 5 comments
Open

A way to restore a previously selected theme. #3

multinerd opened this issue Aug 10, 2017 · 5 comments

Comments

@multinerd
Copy link

multinerd commented Aug 10, 2017

Lets say a user selects a dark theme. When the user exits the app and relaunches, the theme resets to whatever is in code.

Would be nice if the user's preference was persistence without the need for further implementations. I believe Themeable does this and would make a great feature.

@onmyway133
Copy link
Owner

@multinerd Hi, thanks for your suggestion. It is as easy as persisting the theme name to UserDefaults. I can do that 👍

@onmyway133
Copy link
Owner

@multinerd actually I would prefer to use Swift 4 Codable to persist theme, so this will persistence will come together with next version. Hope you understand

@multinerd
Copy link
Author

Sounds good to me. No rush, I have a work around where I save a bool and set theme based on that.

@onmyway133
Copy link
Owner

@multinerd I just updated https://github.com/hyperoslo/Cache to Swift 4 using Codable. It works great. But I don't know if Codable is helpful for Themes, as we have UIImage, UIColor, UIFont, ... It is doable, but saving the whole thing to disk seems heavy. Also, in some apps, the Theme is parsed from json, so it might not be as hardcoded.

One the 2nd thought, I think I just save the name of the current Theme, and give a chance for user to reconfigure Theme based on that name at app launch.

What do you think ?

@multinerd
Copy link
Author

I've completely forgot about the ability to load from JSON. For the most part, I've been using your second approach.

I've added a string property called name to the Theme protocol so that every object that conforms to Theme has a name. That gets saved to userdefaults and and on app launch, we parse that value and set the theme.

When i opened this ticket, i was hoping it would be as simple as saving the name and setting it based on some sort of reflection. You would know better than I if that's possible, I'm still a newb coder.

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

No branches or pull requests

2 participants