2
\$\begingroup\$

I am check first time userDefaults will not save value return 0 else get value from userDefaults

I am checking if userDefaults will not save the value, and If it doesn't, return 0. If it does, then I get the value from userDefaults.

func scaleMeter() {
    let numberPicker = NumberPicker(delegate: self, maxNumber: 100)
    numberPicker.tintColor = .white
    numberPicker.heading = “Select Scale”

    let ageCount = UserDefaults.value(forKey: defaultsKeys.age)
    guard countValue != nil else {
        numberPicker.defaultSelectedNumber = 0
        self.tabBarController?.present(numberPicker, animated: true,  completion: nil)
        return
    }

    numberPicker.defaultSelectedNumber = Int(ageCount as! String)!
    self.tabBarController?.present(numberPicker, animated: true,  completion: nil)

}

Is this a correct approach, having self.tabBarController?.present both inside and outside the guard?

\$\endgroup\$

closed as off-topic by dfhwze, Grajdeanu Alex., Donald.McLean, t3chb0t, Sᴀᴍ Onᴇᴌᴀ Aug 5 at 23:54

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Lacks concrete context: Code Review requires concrete code from a project, with sufficient context for reviewers to understand how that code is used. Pseudocode, stub code, hypothetical code, obfuscated code, and generic best practices are outside the scope of this site." – dfhwze, Grajdeanu Alex., Donald.McLean, t3chb0t, Sᴀᴍ Onᴇᴌᴀ
If this question can be reworded to fit the rules in the help center, please edit the question.

Browse other questions tagged or ask your own question.