realm-swift: Object type 'User' is not managed by the Realm.

The app is crashing on startup and we are not able to reproduce the problem on the test environment. Very critical, happened more than 400 times.

Actual Results

The exception:

Object type 'User' is not managed by the Realm. If using a custom `objectClasses` / `objectTypes` array in your configuration, add `User` to the list of `objectClasses` / `objectTypes`.Issued by Fabric:
Fatal Exception: RLMException
0  CoreFoundation                 0x18113ed8c __exceptionPreprocess
1  libobjc.A.dylib                0x1802f85ec objc_exception_throw
2  Realm                          0x10546a254 RLMSchemaInfo::operator[](NSString*) (RLMClassInfo.mm:94)
3  Realm                          0x1054839e0 RLMGetObjects (RLMObjectStore.mm:215)
4  RealmSwift                     0x10594f880 Realm.objects<A where ...> (A.Type) -> Results<A> (Realm.swift:477)
5  My_App                         0x104a14fdc MyPresenterImpl.sync(onStart : Bool) -> () (MyPresenterImpl.swift:17)
6  My_App                         0x10495b78c MyViewController.viewDidAppear(Bool) -> () (MyViewController.swift:361)
7  My_App                         0x10495bb74 @objc MyViewController.viewDidAppear(Bool) -> () (MyViewController.swift)
8  UIKit                          0x18ad9a7b8 -[UIViewController _setViewAppearState:isAnimating:]
9  UIKit                          0x18adf0b8c -[UINavigationController viewDidAppear:]
10 UIKit                          0x18ad9a7b8 -[UIViewController _setViewAppearState:isAnimating:]
11 UIKit                          0x18afeb47c __64-[UIViewController viewDidMoveToWindow:shouldAppearOrDisappear:]_block_invoke
12 UIKit                          0x18adf0814 -[UIViewController _executeAfterAppearanceBlock]
13 UIKit                          0x18b0f69c4 _runAfterCACommitDeferredBlocks
14 UIKit                          0x18b0ec98c _cleanUpAfterCAFlushAndRunDeferredBlocks
15 UIKit                          0x18b0fd6c0 __34-[UIApplication _firstCommitBlock]_block_invoke_2
16 CoreFoundation                 0x1810e72bc __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__
17 CoreFoundation                 0x1810e6a7c __CFRunLoopDoBlocks
18 CoreFoundation                 0x1810e47b0 __CFRunLoopRun
19 CoreFoundation                 0x181004da8 CFRunLoopRunSpecific
20 GraphicsServices               0x182fe7020 GSEventRunModal
21 UIKit                          0x18afe578c UIApplicationMain
22 My_App                         0x104887a60 main (MigrationBlock.swift:16)
23 libdyld.dylib                  0x180a95fc0 start
Crashed: com.twitter.crashlytics.ios.exception
0  My_App                         0x104a48238 CLSProcessRecordAllThreads (CLSProcess.c:376)
1  My_App                         0x104a48238 CLSProcessRecordAllThreads (CLSProcess.c:376)
2  My_App                         0x104a486ac CLSProcessRecordAllThreads (CLSProcess.c:407)
3  My_App                         0x104a37cec CLSHandler (CLSHandler.m:26)
4  My_App                         0x104a467a4 __CLSExceptionRecord_block_invoke (CLSException.mm:199)
5  libdispatch.dylib              0x180a30ae4 _dispatch_client_callout + 16
6  libdispatch.dylib              0x180a39640 _dispatch_queue_barrier_sync_invoke_and_complete + 56
7  My_App                         0x104a46220 CLSExceptionRecord (CLSException.mm:206)
8  My_App                         0x104a46050 CLSExceptionRecordNSException (CLSException.mm:102)
9  My_App                         0x104a45c50 CLSTerminateHandler() (CLSException.mm:259)
10 libc++abi.dylib                0x1802e937c std::__terminate(void (*)()) + 16
11 libc++abi.dylib                0x1802e8f78 __cxa_rethrow + 144
12 libobjc.A.dylib                0x1802f87ac objc_exception_rethrow + 44
13 CoreFoundation                 0x181004e18 CFRunLoopRunSpecific + 664
14 GraphicsServices               0x182fe7020 GSEventRunModal + 100
15 UIKit                          0x18afe578c UIApplicationMain + 236
16 My_App                         0x104887a60 main (MigrationBlock.swift:16)
17 libdyld.dylib                  0x180a95fc0 start + 4

Steps to Reproduce

Probably crashing during migration, the migration is working ok but Realm hangs on this exception.

Code Sample

Do a query using Realm.objects<A where ...> (A.Type) -> Results<A>. The crash is very generic.

Version of Realm and Tooling

Realm framework version: 3.5.0

Realm Object Server version: No

Xcode version: 9.3

iOS/OSX version: ?

Dependency manager + version: CocoaPods : 1.5.0

Sorry if it is not enough information, but this is everything I have.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 1
  • Comments: 29 (5 by maintainers)

Most upvoted comments

You’re linking RealmSwift into both your app and your test target, which results in two copies of it in the final test bundle since SPM is building it as a static library. This means that RealmSwift.Object in your app and RealmSwift.Object in your tests are two unrelated types, and the subclass defined in the app is not a subclass of the tests’ Object class.

The fix for this is to just remove RealmSwift from the Link Binary With Libraries build phase for your test target (you do still need Realm there and I’m not entirely sure why).

I have the same issue while running tests in XCTest. Here’s a sample project showing the issue: RealmTest.zip

As soon as I call realm.objects(...) I get the exception. If I pass the object type in the realm configuration I get an error saying that the class is a non-Object class.

The error indicates that you are calling realm.objects(User.self), but have explicitly supplied an objectTypes array that does not include User.