0
var window: UIWindow?

 func application(_ application: UIApplication, options: [UIApplicationLaunchOptionsKey : Any]?) -> Bool {
    UserDefaults.standard.register(defaults: [
        bestScoreKey: 1_000_000.0
        ])
    return true
}

func application2(_ application: UIApplication, options: [UIApplicationLaunchOptionsKey : Any]?) -> Bool {
    UserDefaults.standard.register(defaults: [
        coinsKey: 0

        ])

    return true
}

public func application3(_ application: UIApplication, options: [UIApplicationLaunchOptionsKey : Any]?) -> Bool {
   UserDefaults.standard.register(defaults: [

        standardHSKey: 0

        ])

    return true
}

Up above are the three functions I have in AppDelegate.Swift. For some reason the top two functions work but not the bottom one. Here are the ViewControllers below. In this ViewController the data saves.

var fastestScore: Double = UserDefaults.standard.double(forKey: bestScoreKey) {
    didSet {
        UserDefaults.standard.set(fastestScore, forKey: bestScoreKey)
    }
}

var coinsTotal: Int = Int(UserDefaults.standard.double(forKey: coinsKey)) {

    didSet {

    UserDefaults.standard.set(coinsTotal, forKey: coinsKey)

    }
}

However, it does not save the data in this viewController

 var highScore: Int = Int(UserDefaults.standard.double(forKey: standardHSKey){

 didSet {

    UserDefaults.standard.set(highScore, forKey: standardHSKey)

        }
}

I don't know what the problem is. When I substitute an integer for highScore it works but it does not save the data to Userdefaults. Does anyone have any suggestions?

Reid Brown
  • 103
  • 1
  • 4

0 Answers0