Realm 객체 정의
애플리케이션 에서 Realm 객체 를 정의하려면 RealmObject 의 하위 클래스를 만들거나 RealmModel을 구현 합니다.
중요
모든 Realm 객체는 빈 생성자를 제공해야 합니다.
모든 Realm 객체는 Java의
public가시성 수정자나 Kotlin의open가시성 수정자를 사용해야 합니다.
참고
클래스 이름은 최대 57자의 UTF-8 문자로 제한됩니다.
확장 RealmObject
다음 코드 블록은 Frog를 설명하는 Realm 객체를 보여줍니다. 이 Frog 클래스는 RealmObject 클래스를 확장(extends)하므로 Realm에 저장할 수 있습니다.
import io.realm.RealmObject; // To add an object to your Realm Schema, extend RealmObject public class Frog extends RealmObject { private String name; private int age; private String species; private String owner; public Frog(String name, int age, String species, String owner) { this.name = name; this.age = age; this.species = species; this.owner = owner; } public Frog(){} // RealmObject subclasses must provide an empty constructor public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public String getSpecies() { return species; } public void setSpecies(String species) { this.species = species; } public String getOwner() { return owner; } public void setOwner(String owner) { this.owner = owner; } }
import io.realm.RealmObject // providing default values for each constructor parameter // fulfills the need for an empty constructor open class Frog( var name: String? = null, var age: Int = 0, var species: String? = null, var owner: String? = null ) : RealmObject() // To add an object to your Realm Schema, extend RealmObject
구현 RealmModel
다음 코드 블록은 Frog를 설명하는 Realm 객체를 보여줍니다. 이 Frog 클래스는 RealmModel 클래스를 구현(implements)하고 @RealmClass 주석을 사용하기 때문에 Realm에 저장할 수 있습니다.
import io.realm.RealmModel; import io.realm.annotations.RealmClass; public class Frog implements RealmModel { private String name; private int age; private String species; private String owner; public Frog(String name, int age, String species, String owner) { this.name = name; this.age = age; this.species = species; this.owner = owner; } public Frog() {} // RealmObject subclasses must provide an empty constructor public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public String getSpecies() { return species; } public void setSpecies(String species) { this.species = species; } public String getOwner() { return owner; } public void setOwner(String owner) { this.owner = owner; } }
중요
모든 Realm 객체는 public 가시성 수정자를 사용해야 합니다.
import io.realm.RealmModel import io.realm.annotations.RealmClass open class Frog : RealmModel { var name: String? = null var age = 0 var species: String? = null var owner: String? = null constructor(name: String?, age: Int, species: String?, owner: String?) { this.name = name this.age = age this.species = species this.owner = owner } constructor() {} // RealmObject subclasses must provide an empty constructor }
중요
모든 Realm 객체는 open 가시성 수정자를 사용해야 합니다.
팁
RealmObject 메서드 사용
RealmObject 클래스를 확장하여 Realm 객체를 만들면 Realm 객체의 인스턴스에서 RealmObject 클래스 메서드에 동적으로 액세스할 수 있습니다. RealmModel을 구현해서 만든 Realm 객체는 RealmObject 클래스를 통해 동일한 메서드에 정적으로 액세스할 수 있습니다.
// With RealmObject frogRealmObject.isValid(); frogRealmObject.addChangeListener(listener); // With RealmModel RealmObject.isValid(frogRealmModel); RealmObject.addChangeListener(frogRealmModel, listener);
// With RealmObject frogRealmObject?.isValid frogRealmObject?.addChangeListener(listener) // With RealmModel RealmObject.isValid(frogRealmModel) RealmObject.addChangeListener(frogRealmModel, listener)
목록
Realm 객체에는 영역 객체가 아닌 데이터 유형의 목록이 포함될 수 있습니다:
Realm 객체 목록과 달리 이러한 목록에는 null 값이 포함될 수 있습니다. null 값을 허용하지 않아야 하는 경우 @Required 주석을 사용하세요.
import io.realm.RealmList; import io.realm.RealmObject; public class Frog extends RealmObject { private String name; private int age; private String species; private String owner; private RealmList<String> favoriteColors; public Frog(String name, int age, String species, String owner, RealmList<String> favoriteColors) { this.name = name; this.age = age; this.species = species; this.owner = owner; this.favoriteColors = favoriteColors; } public Frog(){} // RealmObject subclasses must provide an empty constructor public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public String getSpecies() { return species; } public void setSpecies(String species) { this.species = species; } public String getOwner() { return owner; } public void setOwner(String owner) { this.owner = owner; } public RealmList<String> getFavoriteColors() { return favoriteColors; } public void setFavoriteColors(RealmList<String> favoriteColors) { this.favoriteColors = favoriteColors; } }
import io.realm.RealmList import io.realm.RealmObject open class Frog : RealmObject { var name: String? = null var age = 0 var species: String? = null var owner: String? = null var favoriteColors : RealmList<String>? = null constructor( name: String?, age: Int, species: String?, owner: String?, favoriteColors: RealmList<String>? ) { this.name = name this.age = age this.species = species this.owner = owner this.favoriteColors = favoriteColors } constructor() {} // RealmObject subclasses must provide an empty constructor }
내장된 객체 필드 정의
Realm은 다른 객체 내에 객체를 중첩하는 기능을 제공합니다. 여기에는 다음과 같은 몇 가지 장점이 있습니다.
동기화를 사용하는 경우 객체는 비정규화된 데이터 모델을 따르는 MongoDB 문서로 변환됩니다.
다른 객체가 포함된 객체를 삭제하면 삭제 작업을 통해 두 객체가 모두 영역에서 제거되므로 사용하지 않는 객체가 영역 파일에 누적되어 사용자 모바일 기기의 귀중한 공간을 차지하지 않습니다.
객체 를 포함하려면 다른 클래스 내에 중첩하려는 클래스에서 @RealmClass 주석의 embedded 속성 을 true 로 설정하다 합니다.
import io.realm.RealmObject; import io.realm.annotations.RealmClass; public class Fly extends RealmObject { private String name; public Fly(String name) { this.name = name; } public Fly() {} // RealmObject subclasses must provide an empty constructor }
import io.realm.RealmObject import io.realm.annotations.RealmClass open class Fly : RealmObject { private var name: String? = null constructor(name: String?) { this.name = name } constructor() {} // RealmObject subclasses must provide an empty constructor }
그런 다음 다른 클래스에서 해당 클래스를 참조할 때마다 Realm은 다음 예시에서와 같이 참조된 클래스를 둘러싸는 클래스 안에 포함시킵니다:
import io.realm.RealmObject; public class Frog extends RealmObject { private String name; private int age; private String species; private String owner; private Fly lastMeal; public Frog(String name, int age, String species, String owner, Fly lastMeal) { this.name = name; this.age = age; this.species = species; this.owner = owner; this.lastMeal = lastMeal; } public Frog(){} // RealmObject subclasses must provide an empty constructor public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public String getSpecies() { return species; } public void setSpecies(String species) { this.species = species; } public String getOwner() { return owner; } public void setOwner(String owner) { this.owner = owner; } public Fly getLastMeal() { return lastMeal; } public void setLastMeal(Fly lastMeal) { this.lastMeal = lastMeal; } }
import io.realm.RealmObject open class Frog : RealmObject { var name: String? = null var age = 0 var species: String? = null var owner: String? = null var lastMeal: Fly? = null constructor( name: String?, age: Int, species: String?, owner: String?, lastMeal: Fly? ) { this.name = name this.age = age this.species = species this.owner = owner this.lastMeal = lastMeal } constructor() {} // RealmObject subclasses must provide an empty constructor }
주석
주석을 사용하여 Realm 객체 모델을 사용자 지정합니다.
기본 키
버전 10.6.0의 새로운 기능: Realm은 기본 키 필드를 자동으로 인덱싱합니다. 이전에는 Realm에서 String의 기본 키만을 자동으로 인덱싱했습니다.
Realm은 @PrimaryKey 주석으로 표시된 필드를 해당 객체 스키마의 기본 키로 취급합니다. 기본 키에는 다음과 같은 제한 사항이 적용됩니다.
객체 모델당 기본 키는 하나만 정의할 수 있습니다.
프라이머리 키 값은 영역에 있는 객체의 모든 인스턴스에서 고유해야 합니다. 중복된 프라이머리 키 값을 삽입하려고 하면 RealmPrimaryKeyConstraintException이 발생합니다.
프라이머리 키 값은 변경되지 않습니다. 객체의 프라이머리 키 값을 변경하려면 원본 객체를 삭제하고 프라이머리 키 값이 다른 새 객체를 삽입해야 합니다.
내장된 객체는 프라이머리 키를 정의할 수 없습니다.
다음 유형 중 하나를 사용하여 기본 키를 만들 수 있습니다:
StringUUIDObjectIdIntegerorintLongorlongShortorshortByteorbyte[]
기본이 아닌 유형은 기본 키 값으로 null 값을 포함할 수 있지만, 각 기본 키 값은 고유해야 하므로 특정 유형의 객체 하나에 대해서만 해당 값을 포함할 수 있습니다. 기존 기본 키가 있는 객체를 영역에 삽입하려고 하면 RealmPrimaryKeyConstraintException이 발생합니다.
Realm은 기본 키 필드를 자동으로 인덱싱하므로 기본 키를 기반으로 객체를 효율적으로 읽고 수정할 수 있습니다.
영역 에 해당 유형의 객체 를 추가한 후에는 객체 유형에 대한 기본 키 필드 를 변경할 수 없습니다. 동기화를 사용하는 경우 백엔드 스키마에서 기본 키 를 정의한 후에는 객체 의 기본 키 필드 를 변경할 수 없습니다.
내장된 객체는 기본 키를 포함할 수 없습니다.
선택적으로 객체 유형에 대한 기본 키를 객체 스키마의 일부로 @PrimaryKey 주석을 사용하여 정의할 수 있습니다:
import io.realm.RealmObject; import io.realm.annotations.PrimaryKey; public class Frog extends RealmObject { private String name; private int age; private String species; private String owner; public Frog(String name, int age, String species, String owner) { this.name = name; this.age = age; this.species = species; this.owner = owner; } public Frog(){} // RealmObject subclasses must provide an empty constructor public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public String getSpecies() { return species; } public void setSpecies(String species) { this.species = species; } public String getOwner() { return owner; } public void setOwner(String owner) { this.owner = owner; } }
import io.realm.RealmObject import io.realm.annotations.PrimaryKey open class Frog : RealmObject { var name : String? = null var age = 0 var species: String? = null var owner: String? = null constructor(name: String?, age: Int, species: String?, owner: String?) { this.name = name this.age = age this.species = species this.owner = owner } constructor() {} // RealmObject subclasses must provide an empty constructor }
필수 필드
import io.realm.RealmObject; import io.realm.annotations.Required; public class Frog extends RealmObject { private String name; private int age; private String species; private String owner; public Frog(String name, int age, String species, String owner) { this.name = name; this.age = age; this.species = species; this.owner = owner; } public Frog(){} // RealmObject subclasses must provide an empty constructor public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public String getSpecies() { return species; } public void setSpecies(String species) { this.species = species; } public String getOwner() { return owner; } public void setOwner(String owner) { this.owner = owner; } }
import io.realm.RealmObject import io.realm.annotations.Required open class Frog : RealmObject { var name: String? = null var age = 0 var species: String? = null var owner: String? = null constructor(name: String?, age: Int, species: String?, owner: String?) { this.name = name this.age = age this.species = species this.owner = owner } constructor() {} // RealmObject subclasses must provide an empty constructor }
선택적 필드
Java 객체 유형 및 코틀린 (Kotlin) null 허용 유형( ? 으로 끝남)으로 표시된 필드는 기본값 null을 허용합니다. 다른 모든 유형(primitive, null을 허용하지 않는 코틀린 (Kotlin) 객체 유형)은 기본값 필수입니다. null 허용 필드 를 @Required 주석으로 표시하여 해당 필드 가 null 값을 보유하지 않도록 할 수 있습니다. RealmLists 는 절대 null을 허용하지 않지만 @Required 주석을 사용하면 기본 유형에서 null을 허용하더라도 목록의 객체가 null 값을 보유하지 못하도록 할 수 있습니다. RealmObject 하위 유형의 RealmList 를 필수 항목으로 표시할 수 없습니다.
다음 유형 중 하나를 필수 항목으로 설정할 수 있습니다:
StringUUIDObjectIdIntegerLongShortByteorbyte[]BooleanFloatDoubleDateRealmList
int 및 RealmList 유형과 같은 초기(Primitive) 유형은 암시적으로 필수 항목입니다. RealmObject 유형의 필드는 항상 null을 허용하며, 필수 항목으로 설정할 수 없습니다.
중요
Kotlin 유형 및 null 허용 여부
코틀린 (Kotlin) 에서는 유형에 ? 접미사를 명시적으로 추가하지 않는 한 기본값 유형에 null을 지정할 수 없습니다. null 허용 유형 에만 주석을 달 수 있습니다. null을 허용하지 않는 유형에 @Required 주석을 사용하면 컴파일에 실패합니다.
@Required 주석으로 달리 지정하지 않는 한 Realm에서 null 허용 필드는 기본적으로 선택 사항입니다. 다음 유형은 null을 허용합니다.
StringDateUUIDObjectIdIntegerLongShortByteorbyte[]BooleanFloatDouble
int 및 long 과 같은 기본 유형은 기본값 으로 null을 허용하지 않으며 null 값으로 설정하다 수 없으므로 null을 허용하도록 설정할 수 없습니다.
코틀린 (Kotlin) 에서 필드 는 코틀린 (Kotlin) ? 연산자 제외:
StringDateUUIDObjectIdDecimal128RealmAny
Int?와(과) 같이 Kotlin ? 연산자로 끝나는 모든 유형을 요구할 수 있습니다.
RealmList 유형은 기본적으로 null을 허용하지 않으며 null을 허용하도록 설정할 수 없습니다.
기본 필드 값
필드에 기본값을 지정하려면 기본 제공 언어 기능을 사용하여 기본값을 할당합니다.
클래스 생성자를 사용하여 기본값을 할당합니다.
import io.realm.RealmObject; public class Frog extends RealmObject { private String name = "Kitty"; private int age; private String species; private String owner; public Frog(String name, int age, String species, String owner) { this.name = name; this.age = age; this.species = species; this.owner = owner; } public Frog(){} // RealmObject subclasses must provide an empty constructor public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public String getSpecies() { return species; } public void setSpecies(String species) { this.species = species; } public String getOwner() { return owner; } public void setOwner(String owner) { this.owner = owner; } }
필드 선언에서 기본값을 지정합니다.
import io.realm.RealmObject open class Frog : RealmObject { var name = "Kitty" var age = 0 var species: String? = null var owner: String? = null constructor(name: String, age: Int, species: String?, owner: String?) { this.name = name this.age = age this.species = species this.owner = owner } constructor() {} // RealmObject subclasses must provide an empty constructor }
참고
기본값 및 null 허용 여부
기본값은 새로 만든 객체가 null 값을 포함할 수 없도록 하지만(기본값 null 을 지정하지 않는 한), 필드의 null 허용 여부에는 영향을 주지 않습니다. 필드에 null을 허용하지 않도록 설정하려면 필수 필드를 참조하세요.
필드 인덱싱
인덱스는 Realm에서 쿼리를 효율적으로 실행할 수 있도록 지원합니다. 인덱스가 없는 경우, Realm은 컬렉션 스캔, 즉 컬렉션의 모든 문서를 스캔하여 쿼리와 일치하는 문서를 선택해야 합니다. 쿼리에 대한 적절한 인덱스가 존재하는 경우 Realm은 인덱스를 사용하여 검사해야 하는 문서 수를 제한할 수 있습니다.
인덱스는 영역 데이터의 작은 부분을 쉽게 탐색할 수 있는 형식으로 저장하는 특수 데이터 구조입니다. 인덱스는 필드 값에 따라 정렬된 특정 필드의 값을 저장합니다. 인덱스 항목의 순서는 효율적인 동등성 매치 및 범위 기반 쿼리 작업을 지원합니다.
인덱스를 추가하면 쓰기 시간이 약간 느려지고 스토리지 및 메모리 오버헤드가 늘어나지만 일부 쿼리의 속도가 빨라질 수 있습니다. 인덱스는 영역 파일의 공간을 차지하므로 속성에 인덱스를 추가하면 영역 파일이 사용하는 디스크 공간이 늘어납니다. 각 인덱스 항목은 최소 12바이트입니다.
다음 유형의 필드를 인덱싱할 수 있습니다:
StringUUIDObjectIdIntegerorintLongorlongShortorshortByteorbyte[]BooleanorboolDateRealmAny
Realm 은 @Index 주석이 달린 필드에 대한 인덱스를 생성합니다.
필드를 인덱싱하려면 @Index 주석을 사용합니다:
import io.realm.RealmObject; import io.realm.annotations.Index; public class Frog extends RealmObject { private String name; private int age; private String species; private String owner; public Frog(String name, int age, String species, String owner) { this.name = name; this.age = age; this.species = species; this.owner = owner; } public Frog(){} // RealmObject subclasses must provide an empty constructor public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public String getSpecies() { return species; } public void setSpecies(String species) { this.species = species; } public String getOwner() { return owner; } public void setOwner(String owner) { this.owner = owner; } }
import io.realm.RealmObject import io.realm.annotations.Index open class Frog : RealmObject { var name: String? = null var age = 0 var species : String? = null var owner: String? = null constructor(name: String?, age: Int, species: String?, owner: String?) { this.name = name this.age = age this.species = species this.owner = owner } constructor() {} // RealmObject subclasses must provide an empty constructor }
필드 무시
모델의 필드를 영역에 저장하지 않으려는 경우 필드를 무시할 수 있습니다.
@Ignore 주석을 사용하여 Realm 객체 모델에서 필드 를 무시합니다.
import io.realm.RealmObject; import io.realm.annotations.Ignore; public class Frog extends RealmObject { private String name; private int age; private String species; // can you ever really own a frog persistently? private String owner; public Frog(String name, int age, String species, String owner) { this.name = name; this.age = age; this.species = species; this.owner = owner; } public Frog(){} // RealmObject subclasses must provide an empty constructor public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public String getSpecies() { return species; } public void setSpecies(String species) { this.species = species; } public String getOwner() { return owner; } public void setOwner(String owner) { this.owner = owner; } }
import io.realm.RealmObject import io.realm.annotations.Ignore open class Frog : RealmObject { var name: String? = null var age = 0 var species: String? = null // can you ever really own a frog persistently? var owner : String? = null constructor(name: String?, age: Int, species: String?, owner: String?) { this.name = name this.age = age this.species = species this.owner = owner } constructor() {} // RealmObject subclasses must provide an empty constructor }
참고
SDK는 정적 및 일시적 필드를 무시합니다.
static 또는 transient로 표시된 필드는 항상 무시되며 @Ignore 주석이 필요하지 않습니다.
필드 이름 바꾸기
기본적으로 Realm은 모델 클래스에 정의된 이름을 사용하여 내부적으로 필드를 나타냅니다. 다음과 같은 이유로 이 동작을 변경하고 싶을 수도 있습니다:
이름 지정 규칙이 서로 다른 플랫폼에서 더 쉽게 작업하고자 하는 경우.
마이그레이션을 강제하지 않고 Kotlin에서 필드 이름을 변경하고자 하는 경우.
모델 클래스에 사용된 이름과 다른 내부 이름을 선택하면 다음과 같은 의미가 있습니다.
마이그레이션은 클래스 및 필드를 만들 때 내부 이름을 사용해야 합니다.
보고된 스키마 오류는 내부 이름을 사용합니다.
필드 이름을 바꾸려면 @RealmField 주석을 사용합니다:
import io.realm.RealmObject; import io.realm.annotations.RealmField; public class Frog extends RealmObject { private String name; private int age; private String species; private String owner; public Frog(String name, int age, String species, String owner) { this.name = name; this.age = age; this.species = species; this.owner = owner; } public Frog(){} // RealmObject subclasses must provide an empty constructor public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public String getSpecies() { return species; } public void setSpecies(String species) { this.species = species; } public String getOwner() { return owner; } public void setOwner(String owner) { this.owner = owner; } }
import io.realm.RealmObject import io.realm.annotations.RealmField open class Frog : RealmObject { var name: String? = null var age = 0 var species: String? = null var owner: String? = null constructor(name: String?, age: Int, species: String?, owner: String?) { this.name = name this.age = age this.species = species this.owner = owner } constructor() {} // RealmObject subclasses must provide an empty constructor }
또는 모듈이나 클래스 수준에서 이름 지정 정책을 할당하여 Realm이 필드 이름을 해석하는 방식을 변경할 수도 있습니다.
모듈 수준 에서 이름 지정 정책 을 정의할 수 있으며, 이는 모듈에 포함된 모든 클래스에 영향을 미칩니다.
import io.realm.annotations.RealmModule; import io.realm.annotations.RealmNamingPolicy; public class MyModule { }
import io.realm.annotations.RealmModule import io.realm.annotations.RealmNamingPolicy open class MyModule
클래스 수준에서 이름 지정 정책을 정의하여 모듈 수준 설정을 재정의할 수도 있습니다:
import io.realm.RealmObject; import io.realm.annotations.RealmClass; import io.realm.annotations.RealmNamingPolicy; public class Frog extends RealmObject { private String name; private int age; private String species; private String owner; public Frog(String name, int age, String species, String owner) { this.name = name; this.age = age; this.species = species; this.owner = owner; } public Frog(){} // RealmObject subclasses must provide an empty constructor public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public String getSpecies() { return species; } public void setSpecies(String species) { this.species = species; } public String getOwner() { return owner; } public void setOwner(String owner) { this.owner = owner; } }
import io.realm.RealmObject import io.realm.annotations.RealmClass import io.realm.annotations.RealmNamingPolicy open class Frog : RealmObject { var name: String? = null var age = 0 var species: String? = null var owner: String? = null constructor(name: String?, age: Int, species: String?, owner: String?) { this.name = name this.age = age this.species = species this.owner = owner } constructor() {} // RealmObject subclasses must provide an empty constructor }
클래스 이름 바꾸기
기본적으로 Realm은 모델 클래스에 정의된 이름을 사용하여 내부적으로 클래스를 나타냅니다. 다음과 같은 이유로 이 동작을 변경하고 싶을 수도 있습니다:
서로 다른 패키지에서 동일한 단순한 이름을 가진 여러 모델 클래스를 지원하고자 하는 경우.
이름 지정 규칙이 서로 다른 플랫폼에서 더 쉽게 작업하고자 하는 경우.
클래스 이름이 Realm에서 지정한 57자 제한보다 긴 경우.
마이그레이션을 강제하지 않고 Kotlin에서 클래스 이름을 변경하고자 하는 경우.
클래스의 이름을 바꾸려면 @RealmClass 주석을 사용합니다:
import io.realm.RealmObject; import io.realm.annotations.RealmClass; public class Frog extends RealmObject { private String name; private int age; private String species; private String owner; public Frog(String name, int age, String species, String owner) { this.name = name; this.age = age; this.species = species; this.owner = owner; } public Frog(){} // RealmObject subclasses must provide an empty constructor public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public String getSpecies() { return species; } public void setSpecies(String species) { this.species = species; } public String getOwner() { return owner; } public void setOwner(String owner) { this.owner = owner; } }
import io.realm.RealmObject import io.realm.annotations.RealmClass open class Frog : RealmObject { var name: String? = null var age = 0 var species: String? = null var owner: String? = null constructor(name: String?, age: Int, species: String?, owner: String?) { this.name = name this.age = age this.species = species this.owner = owner } constructor() {} // RealmObject subclasses must provide an empty constructor }
Realm 스키마에서 클래스 생략
기본적으로 애플리케이션의 Realm 스키마에는 RealmObject를 확장하는 모든 클래스가 포함됩니다. Realm 스키마에 RealmObject를 확장하는 클래스의 하위 집합만 포함하려는 경우, 해당 클래스의 하위 집합을 모듈에 포함하고 해당 모듈을 사용하여 영역을 열 수 있습니다.
import io.realm.annotations.RealmModule; public class MyModule { }
import io.realm.annotations.RealmModule open class MyModule