Check out example codes for "store bool value in nsuserdefaults swift". It will help you in understanding the concepts better.

Code Example 1

struct Settings {

  fileprivate struct Keys {
      static let soundKey = "soundKey"
  }

  static var sound: Bool {
      set {
          UserDefaults.standard.set(newValue, forKey: Keys.soundKey)
      }
      get {
          if UserDefaults.standard.object(forKey: Keys.soundKey) == nil {
              // Value for sound not yet set ... Setting default ...

              UserDefaults.standard.set(true, forKey: Keys.soundKey)
              return true
          }
          return UserDefaults.standard.bool(forKey: Keys.soundKey)
      }

  }
}

Learn ReactJs, React Native from akashmittal.com