如何通过子列表<object>循环?

时间:2015-05-08 06:58:10

标签: swift realm

我尝试在Realm数据库中的子对象中循环遍历列表。每个List<Word>中的topic都有两个元素,但topic.words为空(我如何访问topictopics的每个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"

0 个答案:

没有答案