这是我的代码:
var selectedRoom = try! Realm().objects(Room.self).sorted(byKeyPath: "name")
在
override func viewDidLoad()
中,我有 roomMeasurementLabel.text = "\(selectedRoom)!"
measurementSummaryNameLabel.text = "\(selectedRoom)!"
countertopRoomLabel.text = "\(selectedRoom)!"
roomMeasurementLabel
中的结果与预期的一样,即“厨房”。但是,
measurementSummaryNameLabel
和countertopRoomLabel
中的结果是“结果(然后模型名称空间在小于和大于括号之间)”。所有标签都在它们自己的
UIViewController
中。 最佳答案
realm.objects返回一个results,它是对象的集合,而不是变量名所建议的单个对象。如果您想要第一个对象的selectedroom.first,这是可选的,因为结果可以有0个元素。
关于swift - Realm 未在我的UILabel中显示值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/43497874/