Home how to append entry to userdefualt (swift4)
Reply: 0

how to append entry to userdefualt (swift4)

Sam Burns
1#
Sam Burns Published in 2017-11-15 00:38:59Z

My code right now saves the label that displays a tuple. The problem is that if I changed view controllers and return to this view controller and enter a new entry all of the prior data is deleted. Everything works fine if I don't have to switch view controllers and this is a one page application but my app requires switching of vcs. Someone suggested using UserDefaults.standard.removePersistentDomain but I am not trying to over write the vc when I return from another vc I just want to append to the user defualt that is already there.

    @IBAction func submitText(_ sender: Any) {

        llble.text = String(describing: result) + "\n"
                    UserDefaults.standard.set(llble.text, forKey: "name")
        }

    override func viewDidAppear(_ animated: Bool) {
        let save : String? = UserDefaults.standard.object(forKey: "name") as? String
        if let nameToDisplay = save {
            llble.text = nameToDisplay
        }}
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.332793 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO