我有一个包含所有字符的数据集。然后我有一些列表,我想在其中添加某些字符。
这是我到目前为止在快速代码中得到的:
//
// Lists.swift
//
// Created by Guest on 28.01.19.
// Copyright © 2019 Dom. All rights reserved.
//
// https://academy.realm.io/posts/realm-primary-keys-tutorial/
import Foundation
import RealmSwift
class Lists: Object {
// making use of primary keys
@objc dynamic var listID = UUID().uuidString
@objc dynamic var listName : String = ""
@objc dynamic var listDesc : String = ""
@objc dynamic var listProgressPercentage : Int = 0
// lists all characters associated with this list
var charIDs = List<Characters>()
override static func primaryKey() -> String? {
return "listID"
}
}
和:
//
// Characters.swift
//
// Created by Guest on 28.01.19.
// Copyright © 2019 Dom. All rights reserved.
//
import Foundation
import RealmSwift
class Characters: Object {
// get charID from dictionary.txt later
@objc dynamic var charID = 0
@objc dynamic var character : String = ""
}
我的问题: - 列表仍然是空的。它现在如何添加一个新列表并向“字符”中的对象添加例如 25 个不同的对象引用?
感谢你的帮助!