Skip to content

Instantly share code, notes, and snippets.

@mikeabdullah
Created March 12, 2011 00:47
Show Gist options
  • Save mikeabdullah/866873 to your computer and use it in GitHub Desktop.
Save mikeabdullah/866873 to your computer and use it in GitHub Desktop.
How to make a managed object complain if it's being turned into a fault while KVO observers are still registered with it.
- (void)willTurnIntoFault;
{
[super willTurnIntoFault];
if ([self observationInfo])
{
NSLog(@"%@ has observers:\n%@", [self objectID], [self observationInfo]);
}
}
@jstoffer
Copy link

So, I know that this was posted quite a while ago, but I was just curious if you've ever run into any strange problems having this in your code? I just tried to insert this in all of my managed objects after finding one that was being observed after its context was destroyed. However, when I tried to run with this in all of my objects, I started crashing and don't quite understand why:

thread #3: tid = 0x76b3e, 0x000000010914fd7b libobjc.A.dylib`objc_release + 11, queue = 'NSManagedObjectContext 0x611000190cc0', stop reason = EXC_BAD_ACCESS (code=2, address=0x60406080018d)

  • frame #0: 0x000000010914fd7b libobjc.A.dylib`objc_release + 11
  • frame #1: 0x00000001091510b8 libobjc.A.dylib`(anonymous namespace)::AutoreleasePoolPage::pop(void*) + 488
  • frame #2: 0x00000001096889c6 CoreFoundation`_CFAutoreleasePoolPop + 22
  • frame #3: 0x0000000108041e89 Foundation`-[NSAutoreleasePool drain] + 153
  • frame #4: 0x00000001084d0e71 CoreData`-[_PFManagedObjectReferenceQueue _processReferenceQueue:] + 2065
  • frame #5: 0x000000010856de02 CoreData`__89-[NSManagedObjectContext(_NSInternalNotificationHandling) _registerAyncReferenceCallback]_block_invoke + 98
  • frame #6: 0x00000001084f6f17 CoreData`developerSubmittedBlockToNSManagedObjectContextPerform + 199
  • frame #7: 0x0000000102fcc97e libclang_rt.asan_iossim_dynamic.dylib`asan_dispatch_call_block_and_release + 302
  • frame #8: 0x000000010a18d49b libdispatch.dylib`_dispatch_client_callout + 8
  • frame #9: 0x000000010a173988 libdispatch.dylib`_dispatch_queue_drain + 2215
  • frame #10: 0x000000010a172ea9 libdispatch.dylib`_dispatch_queue_invoke + 601
  • frame #11: 0x000000010a175af2 libdispatch.dylib`_dispatch_root_queue_drain + 1420
  • frame #12: 0x000000010a175561 libdispatch.dylib`_dispatch_worker_thread3 + 111
  • frame #13: 0x000000010a4be4de libsystem_pthread.dylib`_pthread_wqthread + 1129
  • frame #14: 0x000000010a4bc341 libsystem_pthread.dylib`start_wqthread + 13

Have you ever seen anything like this? It's not showing any observers or anything at this point. It was simply adding that code to my objects.

Thanks,
Jaime

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment