HomeiOS Developmentswift - iOS - Realm App crash as a result of migration...

swift – iOS – Realm App crash as a result of migration difficulty


I’m having this crash in manufacturing each time we replace the realm recordsdata. We obtain a brand new realm file each month that has the brand new information for the earlier month and retailer it in disk alongside different months recordsdata with the intention to visualize them to finish person. The primary time we obtain the brand new realm file, customers report a crash on app launching. They reopen it second time and every part goes nicely.
That is the backtrace of the crash:

# Crashlytics - Stack hint
# Utility: ----xxxx--    # Platform: apple
# Model: 1.5.3 (2304031659)
# Situation: e9c74c3deb71fc3c853ba1086c9870f3
# Session: d28417373b544c0b94d0e8926609322b_DNE_0_v2
# Date: -----xxxxx-----

Deadly Exception: RLMException
0  CoreFoundation                 0x9cb4 __exceptionPreprocess
1  libobjc.A.dylib                0x183d0 objc_exception_throw
2  app.                           0x21a4ec +[RLMRealm    performMigrationForConfiguration:error:] + 1097 (RLMRealm.mm:1097)
3  app                            0x58ad10 static Realm.performMigration(for:) + 72 (Migration.swift:72)
4  app.                           0xeb25c specialised RealmDatabaseService.performSchemaMigration(databaseFilePath:) + 32 (RealmDatabaseService.swift:32)
5  app                            0x6590c closure #1 in closure #5 in SynchronizationEngine.synchronizeFiles(_:) + 12 (RealmDatabaseService.swift:12)
6  app.                           0x65518 closure #5 in SynchronizationEngine.synchronizeFiles(_:) + 178 (SynchronizationEngine.swift:178)
7  app.                           0x65b64 partial apply for thunk for @escaping @callee_guaranteed (@in_guaranteed URL, @in_guaranteed DBFileMetadata) -> () (<compiler-generated>)
8  Mix                        0xaf44 Subscribers.Sink.obtain(_:)
9  Mix                        0xaa60 protocol witness for Subscriber.obtain(_:) in conformance Subscribers.Sink<A, B>
10 Mix                        0x11f20 closure #1 in Publishers.ReceiveOn.Inside.obtain(_:)
11 libswiftDispatch.dylib         0xfd4 thunk for @escaping @callee_guaranteed () -> ()
12 libdispatch.dylib              0x2320 _dispatch_call_block_and_release
13 libdispatch.dylib              0x3eac _dispatch_client_callout
14 libdispatch.dylib              0x126a4 _dispatch_main_queue_drain
15 libdispatch.dylib              0x122f4 _dispatch_main_queue_callback_4CF
16 CoreFoundation                 0x98c28 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__
17 CoreFoundation                 0x7a560 __CFRunLoopRun
18 CoreFoundation                 0x7f3ec CFRunLoopRunSpecific
19 GraphicsServices               0x135c GSEventRunModal
20 UIKitCore                      0x39cf58 -[UIApplication _run]
21 UIKitCore                      0x39cbbc UIApplicationMain
22 SwiftUI                        0x1bcc50 OUTLINED_FUNCTION_895
23 SwiftUI                        0x1231ec block_copy_helper.1
24 SwiftUI                        0x10d294 OUTLINED_FUNCTION_901
25 app.                           0x6798 foremost + 12 (App.swift:12)
26 ???                            0x1dba04dec (Manquant)

And that is the performSchemaMigration methodology:

func performSchemaMigration(databaseFilePath path: URL) throws {
    var realmConfig = Realm.Configuration.defaultConfiguration
    realmConfig.fileURL = path
    realmConfig.readOnly = false // we have to set to false with the intention to modify the DB file
    realmConfig.schemaVersion = DatabaseConstants.currentSchemaVersion

    let migrationBlock: MigrationBlock = { migration, oldSchemaVersion in
        if oldSchemaVersion < 2 {
            migration.enumerateObjects(ofType: HRData.className()) { _, newObject in
                if let newObject = newObject {
                    newObject["citizenshipsList"] = Record<String?>()
                    newObject["languagesList"] = Record<String?>()
                }
            }
        }
    }
    realmConfig.migrationBlock = migrationBlock

    attempt Realm.performMigration(for: realmConfig)
}

I attempted altering the preformMigration methodology as documented in realm docs however did not work.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments