4
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Realmでモデルのクラス名を変更したい時は…

Last updated at Posted at 2020-06-20

リファクタリングの一環で、Realmのモデルのクラス名を変更した時のメモです。
(クラス名は変更したいけど、データは引き続き使いたい、というケース。)

RealmClassname を指定すればOK

例えば、 Dog というクラス名を Animal に変更したい時。

open class Dog : RealmObject() {
    var name: String = ""
}

@RealmClass アノテーションを定義して、 name に元のクラス名を書けばOKでした。

@RealmClass(name = "Dog")
open class Animal : RealmObject() {
    var name: String = ""
}

※ ちなみに、@RealmClass("Dog") @RealmClass(value = "Dog") と書いてもOKです。 (ref: https://github.com/realm/realm-java/pull/6149

4
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?