我尝试在Realm数据库中的子对象中循环遍历列表。每个List<Word>
中的topic
都有两个元素,但topic.words
为空(我如何访问topic
中topics
的每个let topics = Realm().objects(Topic)
for topic in topics {
println(topic.description)
//prints Topic {
// name_en = Family;
// words = RLMArray <0x7ff6b4b2a380> (
// [0] Word {
// name_en = Mother;
// },
// [1] Word {
// name_en = Father;
// }
// );
//}
println(topic.words)
//prints
// List<Word> (
//
// )
for word in topic.words {
println(word.name_en)
}
的子列表?
class Word: Object {
dynamic var name_en = ""
var owners: [Topic] {
return linkingObjects(Topic.self, forProperty: "words")
}
override static func primaryKey() -> String? {
return "name_en"
}
}
class Topic: Object {
dynamic var name_en = ""
let words = List<Word>()
override static func primaryKey() -> String? {
return "name_en"
}
}
我在List上做错了什么? 为什么List是空的?
我的模特是:
topic
例如,一个 var topic: Topic? {
didSet {
println(topic!.words)
for word in topic!.words {
println(word.description)
}
}
的代码正常工作:
CLName = raw_input ("\n\nEnter 7 digits CL number !")
if os.path.isdir("/abc/Compiler_Builds/something/%s" % CLName):
print "CL Exists"