领域Objective-C迁移错误

时间:2017-11-08 14:33:19

标签: objective-c realm realm-migration

我通过Crashlytics看到崩溃,并听到客户说应用程序在打开时崩溃了。

这缩小到迁移其中一个领域数据库的应用程序。遗憾的是,我无法重现这个问题,因为我无法理解我所看到的错误。

我有逻辑检查应用程序启动时检查并查看领域是否需要压缩。当这样做时,领域确定需要迁移它并命中迁移块。

    config.migrationBlock = ^(RLMMigration *migration, uint64_t oldSchemaVersion) {
        if (oldSchemaVersion < 17) {
            [migration enumerateObjects:Event.className block:^(RLMObject *oldObject, RLMObject *newObject) {
                NSString *className = [[oldObject[@"endDateTime"] objectSchema] className];
                if ([className isEqualToString:@"DateObject"]) {
                    newObject[@"endDateTime"] = oldObject[@"endDateTime"][@"value"];
                }
            }];
        }
    };

由于我在执行先前的迁移时出现了错误,因此在决定迁移之前,我手动检查是否属性是否属于特定类型。 不幸的是,当这样做时,应该是RLMObject类型的oldObject似乎是根据Crashlytics的NSTaggedDate类型

    [__NSTaggedDate objectSchema]: unrecognized selector sent to instance 0xe41bf592ee000000
    Fatal Exception: NSInvalidArgumentException
    0  CoreFoundation                 0x186419d04 __exceptionPreprocess
    1  libobjc.A.dylib                0x185668528 objc_exception_throw
    2  CoreFoundation                 0x1864271c8 __methodDescriptionForSelector
    3  CoreFoundation                 0x18641f6b0 ___forwarding___
    4  CoreFoundation                 0x18630501c _CF_forwarding_prep_0
    5  MY_mobile_ios_common         0x10199c8c0 __34+[MYRealm getRealmConfigByName:]_block_invoke_2 (MYRealm.m:44)
    6  Realm                          0x1011b6598 -[RLMMigration enumerateObjects:block:] (RLMMigration.mm:99)
    7  MY_mobile_ios_common         0x10199c830 __34+[MYRealm getRealmConfigByName:]_block_invoke (MYRealm.m:40)
    8  Realm                          0x1011b6ab4 -[RLMMigration execute:] (RLMMigration.mm:131)
    9  Realm                          0x1012297ec std::__1::__function::__func<+[RLMRealm realmWithConfiguration:error:]::$_1, std::__1::allocator<+[RLMRealm realmWithConfiguration:error:]::$_1>, void (std::__1::shared_ptr<realm::Realm>, std::__1::shared_ptr<realm::Realm>, realm::Schema&)>::operator()(std::__1::shared_ptr<realm::Realm>&&, std::__1::shared_ptr<realm::Realm>&&, realm::Schema&) (RLMRealm.mm:410)
    10 Realm                          0x10124fa90 std::__1::__function::__func<realm::Realm::update_schema(realm::Schema, unsigned long long, std::__1::function<void (std::__1::shared_ptr<realm::Realm>, std::__1::shared_ptr<realm::Realm>, realm::Schema&)>, std::__1::function<void (std::__1::shared_ptr<realm::Realm>)>, bool)::$_2, std::__1::allocator<realm::Realm::update_schema(realm::Schema, unsigned long long, std::__1::function<void (std::__1::shared_ptr<realm::Realm>, std::__1::shared_ptr<realm::Realm>, realm::Schema&)>, std::__1::function<void (std::__1::shared_ptr<realm::Realm>)>, bool)::$_2>, void ()>::operator()() (memory:4625)
    11 Realm                          0x101181f64 realm::ObjectStore::apply_schema_changes(realm::Group&, unsigned long long, realm::Schema&, unsigned long long, realm::SchemaMode, std::__1::vector<realm::SchemaChange, std::__1::allocator<realm::SchemaChange> > const&, std::__1::function<void ()>) (object_store.cpp:753)
    12 Realm                          0x10124bbb8 realm::Realm::update_schema(realm::Schema, unsigned long long, std::__1::function<void (std::__1::shared_ptr<realm::Realm>, std::__1::shared_ptr<realm::Realm>, realm::Schema&)>, std::__1::function<void (std::__1::shared_ptr<realm::Realm>)>, bool) (functional:1860)
    13 Realm                          0x101226a10 +[RLMRealm realmWithConfiguration:error:] (functional:1860)
    14 MY_mobile_ios_common         0x10199cba0 +[MYRealm mainRealmCompact] (MYRealm.m:137)
    15 MY App                     0x1002b49dc -[AppDelegate compactRealmIfNeeded] (AppDelegate.m:808)
    16 MY App                     0x1002af940 -[AppDelegate application:didFinishLaunchingWithOptions:] (AppDelegate.m:48)

对于我在这里做错了什么的任何想法,我只是删除领域数据库并强迫用户重新开始重新加载数据。

产品名称:Mac OS X. 产品版本:10.12.6 BuildVersion:16G1036

/Applications/Xcode.app/Contents/Developer Xcode 9.1 构建版本9B55

的/ usr / local / bin中/荚 1.3.1 境界(2.10.2) 领域(= 2.10.2)

/斌/庆典 GNU bash,版本3.2.57(1)-release(x86_64-apple-darwin16)

(此处未使用)

的/ usr / local / bin中/ GIT中 git版本2.12.2

1 个答案:

答案 0 :(得分:0)

崩溃日志告诉您,您对[oldObject[@"endDateTime"] objectSchema]的来电看到oldObject[@"endDateTime"]评估为NSDate,而-objectSchema没有回复endDateTime。如果-objectSchema属性可以是不同类型,具体取决于您要更新的模式版本,则需要在对象发送int64_t *id; int *sz; void setupUnionFind(int numNodes) { id = (int64_t *)malloc(numNodes*sizeof(int64_t)); sz = (int *)malloc(numNodes*sizeof(int)); for (int64_t i = 0; i < numNodes; i++) { id[i] = i; sz[i] = 0; } } 之前对该对象进行进一步检查。