영역 by MongoDB

Realm 데이터베이스 정보

Realm은 휴대폰, 정제 또는웨어러블 내부에서 직접 실행되는 mobile database입니다. 이 리포지토리에는 Realm Swift & Realm 오브젝티브-C의 iOS, macOS, tvOS & watchOS 버전에 대한 소스 코드가 있습니다.

Realm을 사용하는 이유

  • 개발자의 직관적인 사용: Realm의 객체 지향 Realm 데이터 모델은 배우기 쉽고, ORM이 필요하지 않으며, 코드 작성 횟수를 줄여줍니다.
  • 모바일용으로 구축: 모든 기능을 갖춘 Realm은 가벼우며 메모리, 디스크 공간, 배터리 수명을 효율적으로 사용합니다.
  • 오프라인 사용을 위한 설계: Realm의 로컬 데이터베이스는 디스크에 데이터를 유지하므로 앱은 온라인과 마찬가지로 오프라인에서도 작동합니다.
  • MongoDB Atlas Device Sync: 사용자, Realm Mobile Sync, 백엔드 전반에서 데이터를 실시간으로 간단하게 동기화할 수 있습니다. 템플릿 애플리케이션 으로 무료로 시작 하고 cloud 백엔드를 생성하세요.

객체 지향: 코드 간소화

Realm은 모바일 개발자를 위해 단순성을 염두에 두고 설계되었습니다. 관용적인 객체 지향 Realm 데이터 모델을 사용하면 수천 줄의 코드를 절약할 수 있습니다.

// Define your models like regular Swift classes
class Dog: Object {
    @Persisted var name: String
    @Persisted var age: Int
}
class Person: Object {
    @Persisted(primaryKey: true) var _id: String
    @Persisted var name: String
    @Persisted var age: Int
    // Create relationships by pointing an Object field to another Class
    @Persisted var dogs: List<Dog>
}
// Use them like regular Swift objects
let dog = Dog()
dog.name = "Rex"
dog.age = 1
print("name of dog: \(dog.name)")

// Get the default Realm
let realm = try! Realm()
// Persist your data easily with a write transaction
try! realm.write {
    realm.add(dog)
}

라이브 객체: 반응형 앱 빌드

Realm의 라이브 객체는 어디에서든 업데이트된 데이터가 모든 곳에서 자동으로 업데이트된다는 것을 의미합니다.

// Open the default realm.
let realm = try! Realm()

var token: NotificationToken?

let dog = Dog()
dog.name = "Max"

// Create a dog in the realm.
try! realm.write {
    realm.add(dog)
}

//  Set up the listener & observe object notifications.
token = dog.observe { change in
    switch change {
    case .change(let properties):
        for property in properties {
            print("Property '\(property.name)' changed to '\(property.newValue!)'");
        }
    case .error(let error):
        print("An error occurred: (error)")
    case .deleted:
        print("The object was deleted.")
    }
}

// Update the dog's name to see the effect.
try! realm.write {
    dog.name = "Wolfie"
}

SwiftUI

Realm은 SwiftUI와 직접 통합되므로 뷰를 업데이트할 필요가 없습니다.

struct ContactsView: View {
    @ObservedResults(Person.self) var persons

    var body: some View {
        List {
            ForEach(persons) { person in
                Text(person.name)
            }
            .onMove(perform: $persons.move)
            .onDelete(perform: $persons.remove)
        }.navigationBarItems(trailing:
            Button("Add") {
                $persons.append(Person())
            }
        )
    }
}

완전 암호화

이동 중 및 미사용 데이터를 암호화하여 가장 민감한 데이터도 안전하게 보호할 수 있습니다.

// Generate a random encryption key
var key = Data(count: 64)
_ = key.withUnsafeMutableBytes { bytes in
    SecRandomCopyBytes(kSecRandomDefault, 64, bytes)
}

// Add the encryption key to the config and open the realm
let config = Realm.Configuration(encryptionKey: key)
let realm = try Realm(configuration: config)

// Use the Realm as normal
let dogs = realm.objects(Dog.self).filter("name contains 'Fido'")

시작하기

Swift 패키지 Manager, CocoaPods, Carthage를 통해 또는 동적 XCFramework를 가져와서 Realm 설치를 지원합니다.

자세한 내용은 Docs 의 자세한 지침을 참조하세요.

cloud 백엔드 및 동기화가 포함된 템플릿 애플리케이션 을 무료로 시작하고 싶으신가요? MongoDB Atlas 계정을 만듭니다.

문서

설명서는 mongodb.com/ko-kr/docs/atlas/device-sdks/sdk/swift/ 에서 찾을 수 있습니다. API 참조는 다음 위치에 있습니다. mongodb.com/ko-kr/docs/realm-sdks/swift/latest/

도움말 얻기

  • 코드에 도움이 필요하세요?: Stack Overflow에서realm 태그 가 붙은 이전 질문을 찾거나 새로운 질문을 하세요. Stack Overflow에 대해 너무 광범위하다고 간주될 수 있는 일반적인 토론의 경우 커뮤니티 포럼 을 사용하세요.
  • 신고할 버그가 있나요? GitHub 이슈를 엽니다. 가능하다면 Realm 버전, 전체 로그, Realm 파일, 문제를 보여주는 프로젝트를 포함하세요.
  • 기능을 요청하시나요? GitHub 이슈를 엽니다. 이 기능의 기능과 필요한 이유를 알려주세요.

Realm 구축

사전 컴파일된 버전을 사용하지 않으려면 소스에서 Realm을 직접 빌드할 수 있습니다.

전제 조건:

  • Realm을 빌드하려면 Xcode 14.1 이상이 필요합니다.
  • Realm문서를 빌드하려면 다음이 필요합니다.

필요한 사전 조건이 모두 갖추어지면 sh build.sh build 명령 하나만으로 Realm을 빌드할 수 있습니다. 코어 바이너리를 다운로드하려면 Realm을 처음 구축할 때 인터넷 연결이 필요합니다. 그러면 build/Release/ 에 Realm.xcframework 및 RealmSwift.xcframework가 생성됩니다.

sh build.sh help 를 실행하여 수행할 수 있는 모든 조치(iOS/osx 빌드, Docs 생성, 테스트 등)을 확인합니다.

기여

자세한 내용은 CONTRIBUTING.md 를 참조하세요!

행동강령

이 프로젝트는 MongoDB 행동 강령 을 준수 합니다. 참여하면 이 강령을 준수하게 됩니다. 용납할 수 없는 행동을 커뮤니티 -컨덕트@mongodb.com으로 신고해 주세요.

라이선스

Realm 오브젝티브-C & Realm Swift는 Apache 2 로 게시됩니다.0 라이선스. Realm Core는 Apache 2 로도 게시됩니다.0 라이선스이며 여기에서 사용할 수 있습니다.

피드백

Realm을 사용하고 있고 만족하신 다면 @realm 을 언급하는 트윗을 보내 생각을 공유해 주세요!

그리고 이 점이 마음에 들지 않는다면 개선했으면 하는 점을 알려주세요. 그러면 문제를 해결할 수 있습니다!