Help! I'm updating an old Xcode project from 2016 and I'm encountering crashes when working with my Realm objects.
I have a game I built in Xcode with swift 3 and put in the AppStore in 2016. It used Realm for my Game objects. It was one of my first projects so recently I decided to revisit the project and update the code, clean it up (I was very new to Swift), make it work with newer devices and screens, fix a couple bugs, add a few features, etc. When going through the updates to the current languages, I can no longer save my Game object because in 2016, the Realm properties were written as:
dynamic var numCorrect: Int = 0
dynamic var numWrong: Int = 0
dynamic var score: Int = 0
dynamic var stars: Int = 0
dynamic var date = NSDate()
...
Now Realm requires "@objc" before "dynamic var". So it's now:
@objc dynamic var numCorrect: Int = 0
@objc dynamic var numWrong: Int = 0
@objc dynamic var score: Int = 0
@objc dynamic var stars: Int = 0
@objc dynamic var date = NSDate()
With this change/addition everything works great. UNTIL I try to update on top of the old/current version in the App Store. It crashes when trying to create a new Game object.
I assume there's some way to migrate but I can't figure it out. The migration guide doesn't address upgrading from an old version of Realm to a new version.
Here's the log:
/Users/realm/workspace/realm_realm-core_release_6.0.6/src/realm/group.hpp:1149: [realm-core-6.0.6] Assertion failed: m_top.size() > s_hist_version_ndx
0 Realm 0x0000000103b5db04 _ZN5realm4utilL18terminate_internalERNSt3__118basic_stringstreamIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE + 28
1 Realm 0x0000000103b5dda0 _ZN5realm4util9terminateEPKcS2_lOSt16initializer_listINS0_9PrintableEE + 324
2 Realm 0x0000000103a97720 _ZN5realm2DB19upgrade_file_formatEbiii + 980
3 Realm 0x0000000103a95130 _ZN5realm2DB7do_openERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEEbbNS_9DBOptionsE + 3092
4 Realm 0x0000000103a97b20 _ZN5realm2DB4openERNS_11ReplicationENS_9DBOptionsE + 244
5 Realm 0x0000000103a9c0a4 _ZN5realm2DB6createERNS_11ReplicationENS_9DBOptionsE + 392
6 Realm 0x0000000103644a44 _ZN5realm5_impl16RealmCoordinator7open_dbEv + 972
7 Realm 0x0000000103643c98 _ZN5realm5_impl16RealmCoordinator12do_get_realmENS_5Realm6ConfigERNSt3__110shared_ptrIS2_EENS_4util8OptionalINS_9VersionIDEEERNS8_17CheckedUniqueLockE + 72
8 Realm 0x0000000103643b30 _ZN5realm5_impl16RealmCoordinator9get_realmENS_5Realm6ConfigENS_4util8OptionalINS_9VersionIDEEE + 268
9 Realm 0x0000000103895ae0 _ZN5realm5Realm16get_shared_realmENS0_6ConfigE + 152
10 Realm 0x00000001037e0434 +[RLMRealm realmWithConfiguration:queue:error:] + 1704
11 RealmSwift 0x0000000104be1660 $sSo8RLMRealmC13configuration5queueABSo0A13ConfigurationC_So012OS_dispatch_C0CSgtKcfCTO + 156
12 RealmSwift 0x0000000104c18aa8 $s10RealmSwift0A0V5queueACSo012OS_dispatch_C0CSg_tKcfC + 140
13 Scrath 0x00000001028afa4c $s6Scrath11AppDelegateC11updateRealmyyF + 680
14 Scrath 0x00000001028af438 $s6Scrath11AppDelegateC11application_29didFinishLaunchingWithOptionsSbSo13UIApplicationC_SDySo0j6LaunchI3KeyaypGSgtF + 288
15 Scrath 0x00000001028af534 $s6Scrath11AppDelegateC11application_29didFinishLaunchingWithOptionsSbSo13UIApplicationC_SDySo0j6LaunchI3KeyaypGSgtFTo + 232
16 UIKitCore 0x00000001c31e478c 66C0BDEB-71CF-3148-AF27-A5B055FAD9A5 + 10893196
17 UIKitCore 0x00000001c31e656c 66C0BDEB-71CF-3148-AF27-A5B055FAD9A5 + 10900844
18 UIKitCore 0x00000001c31ebf68 66C0BDEB-71CF-3148-AF27-A5B055FAD9A5 + 10923880
19 UIKitCore 0x00000001c295eb50 66C0BDEB-71CF-3148-AF27-A5B055FAD9A5 + 1956688
20 UIKitCore 0x00000001c2e29510 _UIScenePerformActionsWithLifecycleActionMask + 112
21 UIKitCore 0x00000001c295f684 66C0BDEB-71CF-3148-AF27-A5B055FAD9A5 + 1959556
22 UIKitCore 0x00000001c295f0b0 66C0BDEB-71CF-3148-AF27-A5B055FAD9A5 + 1958064
23 UIKitCore 0x00000001c295f4a0 66C0BDEB-71CF-3148-AF27-A5B055FAD9A5 + 1959072
24 UIKitCore 0x00000001c295ed28 66C0BDEB-71CF-3148-AF27-A5B055FAD9A5 + 1957160
25 UIKitCore 0x00000001c2963444 66C0BDEB-71CF-3148-AF27-A5B055FAD9A5 + 1975364
26 UIKitCore 0x00000001c2d48080 66C0BDEB-71CF-3148-AF27-A5B055FAD9A5 + 6058112
27 UIKitCore 0x00000001c2e431b4 _UISceneSettingsDiffActionPerformChangesWithTransitionContext + 260
28 UIKitCore 0x00000001c2963180 66C0BDEB-71CF-3148-AF27-A5B055FAD9A5 + 1974656
29 UIKitCore 0x00000001c2e4309c _UISceneSettingsDiffActionPerformActionsWithDelayForTransitionContext + 108
30 UIKitCore 0x00000001c2962fd8 66C0BDEB-71CF-3148-AF27-A5B055FAD9A5 + 1974232
31 UIKitCore 0x00000001c27c8db8 66C0BDEB-71CF-3148-AF27-A5B055FAD9A5 + 294328
32 UIKitCore 0x00000001c27c78b8 66C0BDEB-71CF-3148-AF27-A5B055FAD9A5 + 288952
33 UIKitCore 0x00000001c27c8ae8 66C0BDEB-71CF-3148-AF27-A5B055FAD9A5 + 293608
34 UIKitCore 0x00000001c31ea200 66C0BDEB-71CF-3148-AF27-A5B055FAD9A5 + 10916352
35 UIKitCore 0x00000001c2d6ea50 66C0BDEB-71CF-3148-AF27-A5B055FAD9A5 + 6216272
36 FrontBoardServices 0x00000001c4304bec 039FCB83-A7EC-3872-94E8-DD490434EAEB + 52204
37 FrontBoardServices 0x00000001c432b190 039FCB83-A7EC-3872-94E8-DD490434EAEB + 209296
38 FrontBoardServices 0x00000001c430faac 039FCB83-A7EC-3872-94E8-DD490434EAEB + 96940
39 FrontBoardServices 0x00000001c432ae24 039FCB83-A7EC-3872-94E8-DD490434EAEB + 208420
40 libdispatch.dylib 0x0000000104da318c _dispatch_client_callout + 20
41 libdispatch.dylib 0x0000000104da6964 _dispatch_block_invoke_direct + 368
42 FrontBoardServices 0x00000001c43512b4 039FCB83-A7EC-3872-94E8-DD490434EAEB + 365236
43 FrontBoardServices 0x00000001c4350f60 039FCB83-A7EC-3872-94E8-DD490434EAEB + 364384
44 FrontBoardServices 0x00000001c43514cc 039FCB83-A7EC-3872-94E8-DD490434EAEB + 365772
45 CoreFoundation 0x00000001bf01f860 9624AAFD-5437-3772-A507-0F357875808D + 710752
46 CoreFoundation 0x00000001bf01f7b4 9624AAFD-5437-3772-A507-0F357875808D + 710580
47 CoreFoundation 0x00000001bf01ef04 9624AAFD-5437-3772-A507-0F357875808D + 708356
48 CoreFoundation 0x00000001bf019ca4 9624AAFD-5437-3772-A507-0F357875808D + 687268
49 CoreFoundation 0x00000001bf019660 CFRunLoopRunSpecific + 480
50 GraphicsServices 0x00000001c942a604 GSEventRunModal + 164
51 UIKitCore 0x00000001c31ee15c UIApplicationMain + 1944
52 Scrath 0x00000001028b16a4 main + 80
53 libdyld.dylib 0x00000001bee951ec 95B366E7-F5BD-3308-9416-24B35999029B + 4588!!! IMPORTANT: Please send this log and info about Realm SDK version and other relevant reproduction info to [email protected]
Please, does anyone know how to solve this? It's not like this app is popular but I don't want to require any previous user to delete the app in order to use the new version.
For anyone having this problem, it appears to be a bug with Realm's current version. In my podfile I wrote:
pod 'RealmSwift', '<5.0'
pod 'Realm', '<5.0'
And now my project runs perfectly. Thanks @RobertCrabtree!