0
前些日子,這沒問題,但最近它不起作用。Realm一對多
import UIKit
import RealmSwift
class Dog: Object {
dynamic var name = ""
dynamic var age = 3
}
import UIKit
import RealmSwift
class People: Object {
dynamic var name = ""
dynamic var age = 3
var dogs = List<Dog>()
}
import UIKit
import RealmSwift
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let dog1 = Dog()
dog1.age = 1
dog1.name = "旺財"
let dog2 = Dog()
dog2.age = 3
dog2.name = "大黃"
let p = People()
p.age = 24
p.name = "小明"
let dogs = List<Dog>()
dogs.append(dog1)
dogs.append(dog2)
let realm = try! Realm()
try! realm.write {
realm.add(p)
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
定義'不工作'和你的問題? – Tj3n