这是我的代码:
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
中的结果是“结果(然后是小于和大于括号之间的模型名称 Room)”
所有标签都在它们自己的 UIViewController
中。
最佳答案
Realm.objects 返回一个 Results< Room >,它是对象的集合,而不是像您的变量名称所暗示的那样是单个对象。如果您想要第一个对象,它是 selectedRoom.first,这是可选的,因为 Results 可以有 0 个元素。
关于swift - Realm 没有在我的 UILabel 中显示值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43497874/