Swift如何为离线字典选择本地数据库?

问题描述 投票:0回答:1

我想用swift 4创建一个离线翻译器(字典)。

我需要建议在哪里存储带翻译的单词。翻译的单词现在采用dsl格式,我搜索此特定文件,但平均而言,搜索需要2-3秒。

是否有可能加快搜索速度?如果我把翻译的单词放在核心数据或领域数据库中,它的帮助与否?

ios swift database core-data realm
1个回答
0
投票

Realm Swift使您能够以安全,持久和快速的方式有效地编写应用程序的模型层。这是它的样子:

// Define your models like regular Swift classes
class Dog: Object {
    @objc dynamic var name = ""
    @objc dynamic var age = 0
}
class Person: Object {
    @objc dynamic var name = ""
    @objc dynamic var picture: Data? = nil // optionals supported
    let dogs = List<Dog>()
}

// Use them like regular Swift objects
let myDog = Dog()
myDog.name = "Rex"
myDog.age = 1
print("name of dog: \(myDog.name)")

// Get the default Realm
let realm = try! Realm()

// Query Realm for all dogs less than 2 years old
let puppies = realm.objects(Dog.self).filter("age < 2")
puppies.count // => 0 because no dogs have been added to the Realm yet

// Persist your data easily
try! realm.write {
    realm.add(myDog)
}

// Queries are updated in realtime
puppies.count // => 1

// Query and update from any thread
DispatchQueue(label: "background").async {
    autoreleasepool {
        let realm = try! Realm()
        let theDog = realm.objects(Dog.self).filter("age == 1").first
        try! realm.write {
            theDog!.age = 3
        }
    }
}

对于字典应用程序。我肯定会和Realm一起去。它使用NSFileProtection和加密,因此人们将无法窃取您的翻译数据。

Setup RealmSwift for your projects

热门问题
推荐问题
最新问题