0

Maybe someone of you know how to put clearButton.setTitle parameter in the UserDefaults and after that put to override func viewDidLoad() {

That's parameters which i'm try to put before viewDidLoad to prepare a key, but i think defaults.set is incorrect

let defaults = UserDefaults.standard

let clearB = "clearB"

clearButton.setTitle("Clear", for: .normal )

defaults.set(clearButton.setTitle, forKey: clearB).

Thank you for your help BR Ula

Ula
  • 167
  • 1
  • 2
  • 11
  • What exactly do you want to do here? Do you want to change the title for your button? – NSAdi Oct 24 '17 at 09:37
  • I'm trying to save Label of the button after application will be closed, because there is two versions of the text for this button. – Ula Oct 24 '17 at 12:06

1 Answers1

0
let clearB = "clearB"
clearButton.setTitle("Clear", for: .normal )

UserDefaults.standard.set(clearButton.titleLabel!.text, forKey: clearB)

Retrieve:

if let title = UserDefaults.standard.string(forKey: clearB) {
    clearButton.setTitle(title, for: .normal)
}
Hexfire
  • 5,945
  • 8
  • 32
  • 42
  • Thanks, that's answer which i'm expected but strange that if i'm closing the application after changes of title and open again Title of the button still the same like on start it's not saving previous changes but others like example labels saving changes correct. Maybe you can advise what can be the reason? – Ula Oct 24 '17 at 12:27
  • Fixed . Found the problem. Thank you for the solution. – Ula Oct 24 '17 at 12:54
  • Good. Glad to help! – Hexfire Oct 24 '17 at 12:55