[英]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. 我刚刚使用cocoapods将我的领域从0.91.1更新到0.93.2。
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.
但是realm.objects(Person)返回的对象都是空的。
This is the output of the "printListTapped" function after adding 2 items: 这是添加2个项目后“ printListTapped”函数的输出:
People 人
Person: Empty Value<br/>
Person: Empty Value
I'm really not sure what I'm missing here. 我真的不确定在这里缺少什么。 Thanks in advance.
提前致谢。
The issue here is that your name
property is declared without dynamic
, so it's completely invisible to Realm. 这里的问题是您的
name
属性是在没有dynamic
情况下声明的,因此它对于Realm是完全不可见的。 It should work if you declare it as dynamic var name = "Empty Value"
instead. 如果您将其声明为
dynamic var name = "Empty Value"
它应该可以工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.