Last active
September 4, 2016 21:50
-
-
Save owenzhao/9694c5cd5528b6977e8f57df90aee2a9 to your computer and use it in GitHub Desktop.
Realm的坑(二)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Foo:Object { | |
dynamic var id:Int = 0 | |
dynamic var name:String = "" | |
override class func primaryKey() -> String? { | |
return "id" | |
} | |
} | |
let bar = Foo() | |
bar.id = 1 | |
bar.name = "Marry" // ok | |
let realm = try! Realm() | |
try! realm.write { | |
realm.add(bar) | |
bar.name = "Kelly" // ok | |
} | |
let anotherBar = Foo() | |
anotherBar.id = 1 | |
anotherBar.name = bar.name | |
try! realm.write { | |
realm.add(anotherBar, update:true) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment