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

Refactor Hard-Coded UserDataManager #49

Open
3 tasks
ChoiysApple opened this issue Jan 17, 2023 · 0 comments
Open
3 tasks

Refactor Hard-Coded UserDataManager #49

ChoiysApple opened this issue Jan 17, 2023 · 0 comments
Assignees
Labels
Refactor Architecture or Logic needs to be changed for clean code / sustainability

Comments

@ChoiysApple
Copy link
Owner

ChoiysApple commented Jan 17, 2023

Issue

From UserDataManager.swift, method to access UserDefault data is like:

func setPopCount(popCount: Int) {
    userDefaults.set(popCount, forKey: UserDataKey.popCount)
}

func setPopVisibility(popVisibility: Bool) {
    userDefaults.set(popVisibility, forKey: UserDataKey.popCountVisibility)
}

func setIsNotInitialLaunch(isNotFirst: Bool) {
    userDefaults.set(isNotFirst, forKey: UserDataKey.isNotFirstLaunch)
}

... 

and the same goes to all other UserDataKey

Solution

Refactor those methods using Generic:

// Sample Code
func setUserData <T>(key: String, value: T) -> Bool {
    if userDefaults.set(value, forKey: key) {
        return true // Success

    } else {
        return false // Failed
    }
}

List

  • Getters
  • Setters
  • Show All Data
@ChoiysApple ChoiysApple added the Refactor Architecture or Logic needs to be changed for clean code / sustainability label Jan 17, 2023
@ChoiysApple ChoiysApple self-assigned this Jan 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Refactor Architecture or Logic needs to be changed for clean code / sustainability
Projects
None yet
Development

No branches or pull requests

1 participant