Mibtar Mibtar - 1 year ago 81
iOS Question

realm io returns empty objects (realm 0.93.2)

I've just update my realm to 0.93.2 from 0.91.1 using cocoapods.

I now get empty objects in my query results. So I made a simple app just to test from scratch but I still get the same results.

Here is my test code (basically just one textfield and two buttons (add and print):

import UIKit
import RealmSwift

class Person: Object {
var name = "Empty Value"

class ViewController: UIViewController {

@IBOutlet weak var nameTextField: UITextField!

var realm = Realm()

override func viewDidLoad() {

override func didReceiveMemoryWarning() {

@IBAction func addTapped(sender: UIButton) {
var person = Person()
person.name = nameTextField.text

realm.write {
println("Person added: \(person.name)")

@IBAction func printListTapped(sender: UIButton) {
for person in realm.objects(Person) {
println("Person: \(person.name)")

The data is saved to the database, as they're seen in the Realm Browser.
But the objects returned by realm.objects(Person) are all empty.

This is the output of the "printListTapped" function after adding 2 items:


Person: Empty Value<br/>
Person: Empty Value

I'm really not sure what I'm missing here. Thanks in advance.

Answer Source

The issue here is that your name property is declared without dynamic, so it's completely invisible to Realm. It should work if you declare it as dynamic var name = "Empty Value" instead.