-
Realm이란?
- Realm사에서 만든 Mobile Database
- 가벼운 객체 컨테이너
- RDBMS처럼 쿼리, 필터링, 관계형(상호 연결)이 가능하고 저장이 됨
- 라이브 오브젝트이며 반응형 객체임
- 기기와 애플리케이션 사이에서 매끄럽게 동기화 되며 스레드에서 안전하게 접근 가능
- String Key 보안체계 확립
- Android, iOS, Xamarin, React Native에서 이용가능
- 항상 오프라인 우선 방식으로 동작
간단한 예제(Swift)
1234567891011121314151617181920212223242526272829303132333435363738394041424344import RealmSwift// Define your models like regular Swift classesclass Dog: Object {dynamic var name = ""dynamic var age = 0}class Person: Object {dynamic var name = ""dynamic var picture: Data? = nil // optionals supportedlet dogs = List<Dog>()}// Use them like regular Swift objectslet myDog = Dog()myDog.name = "Rex"myDog.age = 1print("name of dog: \(myDog.name)")// Get the default Realmlet realm = try! Realm()// Query Realm for all dogs less than 2 years oldlet puppies = realm.objects(Dog.self).filter("age < 2")puppies.count // => 0 because no dogs have been added to the Realm yet// Persist your data easilytry! realm.write {realm.add(myDog)}// Queries are updated in realtimepuppies.count // => 1// Query and update from any threadDispatchQueue(label: "background").async {autoreleasepool {let realm = try! Realm()let theDog = realm.objects(Dog.self).filter("age == 1").firsttry! realm.write {theDog!.age = 3}}}cs 출처