Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 斯威夫特,你如何将对象数组保存到领域?_Swift_Realm - Fatal编程技术网

Swift 斯威夫特,你如何将对象数组保存到领域?

Swift 斯威夫特,你如何将对象数组保存到领域?,swift,realm,Swift,Realm,我对斯威夫特王国不熟悉。下面是我保存单个对象的方法 let realm = try! Realm() func savePerson(_ person: Person){ do{ try realm.write { realm.add(person) } }catch{ print(error.localizedDescription)

我对斯威夫特王国不熟悉。下面是我保存单个对象的方法

let realm = try! Realm()

    func savePerson(_ person: Person){
        do{
            try realm.write {
                realm.add(person)
            }
        }catch{
            print(error.localizedDescription)
        }
    }
是否有保存数组的方法

func savePersonList(_ personList: []){
    do{
        try realm.write{
            // HOW??
        }
    }catch{

    }
}

只需使用
添加
。它也接受一个
序列
。真的吗?我不知道,是的。继续尝试吧。你有一个类可以成为域中的表吗?只需使用
add
。它也接受一个
序列
。真的吗?我不知道,是的。去试试吧。你有没有一个类可以成为领域中的表?