Ten*_*uki 8 xcode realm ios swift
我最近创建了一个新的分支,并试图重构很多我的代码给Realm
了一枪CoreData
.但到目前为止,我还没有运气得到我的代码.
首先,在shared_realm.cpp中抛出异常.抛出错误的代码行是:
if (realm->config().schema_version != config.schema_version && config.schema_version != ObjectStore::NotVersioned) {
throw MismatchedConfigException("Realm at path already opened with different schema version.");
}
Run Code Online (Sandbox Code Playgroud)
如果我跳过此异常,它将捕获以下代码中的第二行代码:
class func getAllCategories() -> Results<Category> {
let realm = try! Realm()
let categories = realm.objects(Category)
return categories
}
Run Code Online (Sandbox Code Playgroud)
并抛出此错误消息:
致命错误:'试试!' 表达式意外地引发了一个错误:错误Domain = io.realm Code = 1"已使用不同架构版本打开的路径中的域".UserInfo = {NSLocalizedDescription =已使用不同架构版本打开的路径中的域.错误代码= 1}
我对Realm是全新的,所以任何帮助都表示赞赏.我从文档中了解到Realm()
,这是访问默认数据库的正确方法,这对我目前的用途来说很好.起初我认为也许必须传递一个领域,但我从在线示例中看到,情况似乎并非如此.
我已经清理,更改了模拟器,甚至更新了Xcode.我还尝试将这行代码注释回来:
// FIXME - enable schema comparison
/*if (realm->config().schema != config.schema) {
throw MismatchedConfigException("Realm at path already opened with different schema");
}*/
Run Code Online (Sandbox Code Playgroud)
无济于事.感觉很丢失,所以任何方向都值得赞赏.
路径的架构版本在打开后无法更改,因此您需要在使用 调用路径之前更改架构setSchemaVersion
。
setSchemaVersion(1, realmPath: Realm.defaultPath) { (migration, oldSchemaVersion) -> Void in
if oldSchemaVersion < 1 {
migration.enumerate(Category.className(), { (oldObject, newObject) -> Void in
let constant = oldObject!["constant"] as! String
newObject!["constant"] = constant
})
}
}
Run Code Online (Sandbox Code Playgroud)