Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/93.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 致命错误:Can';不开放领域_Ios_Swift_Realm_Realm Mobile Platform - Fatal编程技术网

Ios 致命错误:Can';不开放领域

Ios 致命错误:Can';不开放领域,ios,swift,realm,realm-mobile-platform,Ios,Swift,Realm,Realm Mobile Platform,我正在IOS上工作。我正在前端使用领域数据库。在我对领域模型和所有与之相关的文件做了一些更改之前,它一直工作得很好。我刚刚在这些文件中添加了一个字段 现在我在下面的代码中得到一个错误“致命错误:无法打开领域” fileprivate func getRealm() -> Realm { // get default configuration realm do { return try Realm() } catch { Swift.

我正在IOS上工作。我正在前端使用领域数据库。在我对领域模型和所有与之相关的文件做了一些更改之前,它一直工作得很好。我刚刚在这些文件中添加了一个字段

现在我在下面的代码中得到一个错误“致命错误:无法打开领域”

fileprivate func getRealm() -> Realm {
    // get default configuration realm
    do {
        return try Realm()
    } catch {
        Swift.fatalError("Can't open realm")  //Fatal Error :Can't open realm
    }
}
有人能告诉我这个错误的可能原因吗。
提前感谢。

如果对领域模型进行了更改,则需要增加架构版本,并且可能需要提供迁移块。有关详细信息,请参阅官方文件

// Inside your [AppDelegate didFinishLaunchingWithOptions:]

RLMRealmConfiguration *config = [RLMRealmConfiguration defaultConfiguration];
// Set the new schema version. This must be greater than the previously used
// version (if you've never set a schema version before, the version is 0).
config.schemaVersion = 1;

// Set the block which will be called automatically when opening a Realm with a
// schema version lower than the one set above
config.migrationBlock = ^(RLMMigration *migration, uint64_t oldSchemaVersion) {
    // We haven’t migrated anything yet, so oldSchemaVersion == 0
    if (oldSchemaVersion < 1) {
        // Nothing to do!
        // Realm will automatically detect new properties and removed properties
        // And will update the schema on disk automatically
    }
};

// Tell Realm to use this new configuration object for the default Realm
[RLMRealmConfiguration setDefaultConfiguration:config];

// Now that we've told Realm how to handle the schema change, opening the file
// will automatically perform the migration
[RLMRealm defaultRealm];
//在[AppDelegate didFinishLaunchingWithOptions:]
RLMRealmConfiguration*config=[RLMRealmConfiguration defaultConfiguration];
//设置新的架构版本。该值必须大于以前使用的值
//版本(如果以前从未设置过架构版本,则版本为0)。
config.schemaVersion=1;
//设置在打开具有
//架构版本低于上面设置的版本
config.migrationBlock=^(RLMMiglation*迁移,uint64\u t旧模式){
//我们还没有迁移任何内容,所以oldSchemaVersion==0
if(oldschemaversation<1){
//无事可做!
//领域将自动检测新属性和删除的属性
//并将自动更新磁盘上的架构
}
};
//告诉领域将此新配置对象用于默认领域
[RLMRealmConfiguration setDefaultConfiguration:config];
//现在我们已经告诉Realm如何处理模式更改,打开文件
//将自动执行迁移
[RLMRealm defaultRealm];

如果对领域模型进行了更改,则需要增加架构版本,并且可能需要提供迁移块。有关详细信息,请参阅官方文件

// Inside your [AppDelegate didFinishLaunchingWithOptions:]

RLMRealmConfiguration *config = [RLMRealmConfiguration defaultConfiguration];
// Set the new schema version. This must be greater than the previously used
// version (if you've never set a schema version before, the version is 0).
config.schemaVersion = 1;

// Set the block which will be called automatically when opening a Realm with a
// schema version lower than the one set above
config.migrationBlock = ^(RLMMigration *migration, uint64_t oldSchemaVersion) {
    // We haven’t migrated anything yet, so oldSchemaVersion == 0
    if (oldSchemaVersion < 1) {
        // Nothing to do!
        // Realm will automatically detect new properties and removed properties
        // And will update the schema on disk automatically
    }
};

// Tell Realm to use this new configuration object for the default Realm
[RLMRealmConfiguration setDefaultConfiguration:config];

// Now that we've told Realm how to handle the schema change, opening the file
// will automatically perform the migration
[RLMRealm defaultRealm];
//在[AppDelegate didFinishLaunchingWithOptions:]
RLMRealmConfiguration*config=[RLMRealmConfiguration defaultConfiguration];
//设置新的架构版本。该值必须大于以前使用的值
//版本(如果以前从未设置过架构版本,则版本为0)。
config.schemaVersion=1;
//设置在打开具有
//架构版本低于上面设置的版本
config.migrationBlock=^(RLMMiglation*迁移,uint64\u t旧模式){
//我们还没有迁移任何内容,所以oldSchemaVersion==0
if(oldschemaversation<1){
//无事可做!
//领域将自动检测新属性和删除的属性
//并将自动更新磁盘上的架构
}
};
//告诉领域将此新配置对象用于默认领域
[RLMRealmConfiguration setDefaultConfiguration:config];
//现在我们已经告诉Realm如何处理模式更改,打开文件
//将自动执行迁移
[RLMRealm defaultRealm];

上述问题是由于领域数据库不一致造成的。我通过添加一个字段更改了模型的结构。因此,模型有10个字段,但我的应用程序中的领域数据库有9个字段,因为应用程序是在更改之前构建的

我解决了这个问题,只需重新安装在手机中重新生成领域数据库的应用程序,从而获得了一致的模型和数据库

如果你的应用还没有上线,上面的解决方法可能会很好。但是,如果你的应用已经被其他用户使用,那么他们将不得不在更新时重新安装该应用,这可能会给用户带来糟糕的用户体验

理想情况下,您应该为新更改编写迁移块。
希望大家都明白。

上述问题是由于领域数据库不一致造成的。我通过添加一个字段更改了模型的结构。因此,模型有10个字段,但我的应用程序中的领域数据库有9个字段,因为应用程序是在更改之前构建的

我解决了这个问题,只需重新安装在手机中重新生成领域数据库的应用程序,从而获得了一致的模型和数据库

如果你的应用还没有上线,上面的解决方法可能会很好。但是,如果你的应用已经被其他用户使用,那么他们将不得不在更新时重新安装该应用,这可能会给用户带来糟糕的用户体验

理想情况下,您应该为新更改编写迁移块。
希望大家都明白。

好的,谢谢!好的,谢谢!将检查