Home / IOS Development / Do you save what is presented on the Realm screen? : iOSProgramming

Do you save what is presented on the Realm screen? : iOSProgramming



I have a feature that picks up a word and gives it to me once a day:

func updateWordOfTheDay() -> VocabData {

let wordOfTheDay = retrieveVocab() // gets vocabulary from a file

saveToUserDefaults(with: wordOfTheDay)

updateLabels(using: wordOfTheDay)

return wordOfTheDay

}

This shows the word on the screen, but I want the option to have that word stored in Realm at the click of a button.

However, I’m not sure how to capture the current word in my button function:

@ IBAction func favouritePressed(_ sender: UIButton) {

// tried to capture words in two ways:

let savedWord = updateWordOftheDay() // but it gives me a whole new word, not what’s displayed on the screen

let savedWord = readFromUserDefaults() // tries to retrieve the specific word, but when you print, it returns blank: “()”

}

Can anyone point me in the right direction?

Thanks!


Source link