Luca Nicoletti Luca Nicoletti - 1 year ago 58
Swift Question

Realm data stored on UITextField are empty, print(entry) works

I have a Realm database, in which I store my entries. Storing & querying work without any problems. I know in Swift Realm Results are lazy but I can't get why this is happening.
My code:

newsItems = databaseHelper.retriveAllNews()
//[...] this is on tableView method
let currentNew = newsItems[indexPath.row]
newsCell.newsTitle.text = currentNew.title
newsCell.newsText.text =

statement works perfectly and I get all the info stored in the
object, but when I set the info into the UITextField
them are displayed empty, as the Result have not been loaded yet.

Any suggestion?

Answer Source

The most likely cause of the problem you're seeing is omitting the dynamic modifier from the property declarations in your model class. The dynamic modifier is necessary to ensure that Realm has an opportunity to intercept access to the properties, giving Realm an opportunity to read / write the data from the file on disk. Omitting these properties results in the Swift compiler accessing the instance variables directly, cutting Realm out of the loop.