Mibtar
Mibtar

Reputation: 13

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() {
        super.viewDidLoad()
        println(realm.path)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }

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

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

    @IBAction func printListTapped(sender: UIButton) {
        println("\n\nPeople\n")
        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:

People

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

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

Upvotes: 1

Views: 760

Answers (1)

segiddins
segiddins

Reputation: 4120

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.

Upvotes: 2

Related Questions