我们如何给出领域模型字段的默认值?
示例:
class Demo extends RealmObject{
private String id; // I want to set this id to a uuid
private boolean isVisibile; // set this to default as true
}
答案 0 :(得分:4)
class Demo extends RealmObject{
public Demo() {
id = UUID.randomUuid().toString();
isVisible = true;
}
@PrimaryKey
private String id; // I want to set this id to a uuid
private boolean isVisibile; // set this to default as true
}
应该运行Realm 2.0 +