在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):realm/realm-swift开源软件地址(OpenSource Url):https://github.com/realm/realm-swift开源编程语言(OpenSource Language):Objective-C 56.6%开源软件介绍(OpenSource Introduction):Realm is a mobile database that runs directly inside phones, tablets or wearables. This repository holds the source code for the iOS, macOS, tvOS & watchOS versions of Realm Swift & Realm Objective-C. Why Use Realm
Object-Oriented: Streamline Your CodeRealm was built for mobile developers, with simplicity in mind. The idiomatic, object-oriented data model can save you thousands of lines of code. // 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)
} Live Objects: Build Reactive AppsRealm’s live objects mean data updated anywhere is automatically updated everywhere. // 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"
} SwiftUIRealm integrates directly with SwiftUI, updating your views so you don't have to. 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())
}
)
}
} Fully EncryptedData can be encrypted in-flight and at-rest, keeping even the most sensitive data secure. // 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'") Data SyncThe Device Sync service makes it simple to keep data in sync across users, devices, and your backend in real-time. Getting StartedWe support installing Realm via Swift Package Manager, CocoaPods, Carthage, or by importing a dynamic XCFramework. For more information, see the detailed instructions in our docs. DocumentationThe documentation can be found at docs.mongodb.com/realm/sdk/ios/. Getting Help
Building RealmIn case you don't want to use the precompiled version, you can build Realm yourself from source. Prerequisites:
Once you have all the necessary prerequisites, building Realm.framework just takes a single command: Run ContributingSee CONTRIBUTING.md for more details! Code of ConductThis project adheres to the MongoDB Code of Conduct. By participating, you are expected to uphold this code. Please report unacceptable behavior to [email protected]. LicenseRealm Objective-C & Realm Swift are published under the Apache 2.0 license. This product is not being made available to any person located in Cuba, Iran, North Korea, Sudan, Syria or the Crimea region, or to any other person that is not eligible to receive the product under U.S. law. FeedbackIf you use Realm and are happy with it, please consider sending out a tweet mentioning @realm to share your thoughts! And if you don't like it, please let us know what you would like improved, so we can fix it! |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论