My app is in production and I've been getting a few crashes on Crashlytics when trying to cast the first element of a festRequest to a certain entity. I've not been able to recreate this crash no matter how hard I try.
static func getSettings() -> NotificationSettingsMO {
var settings: NotificationSettingsMO!
let moc = DataController.shared.managedObjectContext
moc.performAndWait {
do {
let fetchRequest = NSFetchRequest<NSFetchRequestResult>(entityName: "NotificationSettings")
settings = try moc.fetch(fetchRequest).first as! NotificationSettingsMO
} catch {
print(error)
}
}
return settings
The crash happens when trying to cast the first element of the request to NotificationSettingsMO and I'm sure the entity exists since I create it when the user is created. This also only happens to a small percentage of users, but since it crashes the app I want to try and figure out what is causing it.
EDIT: I've attached the crash log
Crashed: com.apple.main-thread
0 MyApp 0x100073360 specialized static NotificationSettingsMO.(getSettings() -> NotificationSettingsMO).(closure #1) (NotificationSettingsMO.swift:25)
1 MyApp 0x10007309c partial apply for static NotificationSettingsMO.(getSettings() -> NotificationSettingsMO).(closure #1) (NotificationSettingsMO.swift)
2 CoreData 0x18311d08c developerSubmittedBlockToNSManagedObjectContextPerform + 196
3 CoreData 0x18311cf54 -[NSManagedObjectContext performBlockAndWait:] + 220
4 MyApp 0x100072fa8 specialized static NotificationSettingsMO.getSettings() -> NotificationSettingsMO (NotificationSettingsMO.swift)
5 MyApp 0x1000d6190 AppDelegate.getDataOnLaunch() -> () (AppDelegate.swift)
6 MyApp 0x1000da4bc specialized AppDelegate.application(UIApplication, didFinishLaunchingWithOptions : [UIApplicationLaunchOptionsKey : Any]?) -> Bool (AppDelegate.swift:99)
7 MyApp 0x1000d3eb8 #objc AppDelegate.application(UIApplication, didFinishLaunchingWithOptions : [UIApplicationLaunchOptionsKey : Any]?) -> Bool (AppDelegate.swift)
8 UIKit 0x1863f29c0 -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 400
9 UIKit 0x186622184 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 2904
10 UIKit 0x1866265f0 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1684
11 UIKit 0x186623764 -[UIApplication workspaceDidEndTransaction:] + 168
12 FrontBoardServices 0x182bbf7ac __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 36
13 FrontBoardServices 0x182bbf618 -[FBSSerialQueue _performNext] + 168
14 FrontBoardServices 0x182bbf9c8 -[FBSSerialQueue _performNextFromRunLoopSource] + 56
15 CoreFoundation 0x1811d509c __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
16 CoreFoundation 0x1811d4b30 __CFRunLoopDoSources0 + 540
17 CoreFoundation 0x1811d2830 __CFRunLoopRun + 724
18 CoreFoundation 0x1810fcc50 CFRunLoopRunSpecific + 384
19 UIKit 0x1863eb94c -[UIApplication _run] + 460
20 UIKit 0x1863e6088 UIApplicationMain + 204
21 MyApp 0x10001ee18 main (Measurement+Network.swift:26)
22 libdispatch.dylib 0x180c9a8b8 (Missing)
The object does not exists so it crashes. Personally I HATE force casting in swift. The whole point of optionals is to help you manage when something is nil. Putting as! in your code is asking the program to crash. I would suggest removing it and replacing it with an if let. If you are 100% sure that it will never be nil then you should still use an if let and in the else report to crash service that it happened (use Crashlytics recordError - it will show up along with your crashes).
As for your statement:
I'm sure the entity exists since I create it when the user is created
to put it bluntly - you are wrong. Computers are always right and humans are always wrong.
Here are the possible reasons why:
There was an error saving it to core data I suspect that like most programs when you saved the object to core data you did not check for errors - or if you did you didn't really know what to do with the error. If you were smart you would have logged it. The most common error to get is lack of space on the hard disk. If the object wasn't saved in the first place then it wouldn't be there when you fetch it.
The object was there but was deleted. If you have anywhere in your code that deletes this object, then consider the possibility that it was deleted before this code ran. Look for multithreading and race conditions.
The object wasn't save yet. If you have ANY multithreading in the app you should consider the possibility that there is a race condition.
Any of these situations would cause crashes in the 0-3% range.
Related
I have an app with very strange crashes that I have been unable to reproduce. I see these crashes in Xcode Organizer and in AppStore connect but not in crash tools (I tried Sentry and Bugsnag).
As far as I understand crash logs, crash occurs in applicationWillResignActive.
Incident Identifier: A15332F7-C7E6-4618-9FEF-7A2E6AD013FF
Hardware Model: iPhone14,5
Process: MyApp [1533]
Path: /private/var/containers/Bundle/Application/408766C6-5645-4592-9D89-CB8DE5D71A76/MyApp.app/MyApp
Identifier: com.myapp.identifier
Version: 1.2.3 (123)
AppStoreTools: 13A1030d
AppVariant: 1:iPhone14,5:15
Code Type: ARM-64 (Native)
Role: Non UI
Parent Process: launchd [1]
Coalition: com.myapp.identifier [899]
Date/Time: 2021-11-12 08:04:45.3781 +0300
Launch Time: 2021-11-12 01:20:00.0202 +0300
OS Version: iPhone OS 15.0 (19A346)
Release Type: User
Baseband Version: 1.00.03
Report Version: 104
Exception Type: EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0x0000000000000001, 0x0000000100602734
Exception Note: EXC_CORPSE_NOTIFY
Terminating Process: exc handler [1533]
Triggered by Thread: 0
Thread 0 name:
Thread 0 Crashed:
0 MyApp 0x0000000100602734 specialized AppDelegate.applicationWillResignActive(_:) + 168
1 MyApp 0x00000001005ff40c AppDelegate.applicationWillTerminate(_:) + 12 (<compiler-generated>:0)
2 MyApp 0x00000001005ff40c #objc AppDelegate.applicationWillTerminate(_:) + 56
3 UIKitCore 0x0000000186a34ddc -[UIApplication _terminateWithStatus:] + 244 (UIApplication.m:6876)
4 UIKitCore 0x0000000186122854 -[_UISceneLifecycleMultiplexer _evalTransitionToSettings:fromSettings:forceExit:withTransitionStore:] + 128 (_UISceneLifecycleMultiplexer.m:808)
5 UIKitCore 0x00000001863172e4 -[_UISceneLifecycleMultiplexer forceExitWithTransitionContext:scene:] + 224 (_UISceneLifecycleMultiplexer.m:482)
6 UIKitCore 0x0000000186a31a5c -[UIApplication workspaceShouldExit:withTransitionContext:] + 212 (UIApplication.m:3792)
7 FrontBoardServices 0x0000000195150c48 __63-[FBSWorkspaceScenesClient willTerminateWithTransitionContext:]_block_invoke_2 + 80 (FBSWorkspaceScenesClient.m:331)
8 FrontBoardServices 0x000000019510b6c4 -[FBSWorkspace _calloutQueue_executeCalloutFromSource:withBlock:] + 240 (FBSWorkspace.m:352)
9 FrontBoardServices 0x0000000195150be0 __63-[FBSWorkspaceScenesClient willTerminateWithTransitionContext:]_block_invoke + 132 (FBSWorkspaceScenesClient.m:328)
10 libdispatch.dylib 0x0000000183346950 _dispatch_client_callout + 20 (object.m:560)
11 libdispatch.dylib 0x000000018334a3e8 _dispatch_block_invoke_direct + 264 (queue.c:489)
12 FrontBoardServices 0x000000019510cfa4 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 48 (FBSSerialQueue.m:157)
13 FrontBoardServices 0x000000019510c3e4 -[FBSSerialQueue _targetQueue_performNextIfPossible] + 220 (FBSSerialQueue.m:181)
14 FrontBoardServices 0x00000001951109f4 -[FBSSerialQueue _performNextFromRunLoopSource] + 28 (FBSSerialQueue.m:194)
15 CoreFoundation 0x00000001836f6030 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 28 (CFRunLoop.c:1972)
16 CoreFoundation 0x0000000183706cf0 __CFRunLoopDoSource0 + 208 (CFRunLoop.c:2016)
17 CoreFoundation 0x0000000183640ff8 __CFRunLoopDoSources0 + 268 (CFRunLoop.c:2053)
18 CoreFoundation 0x0000000183646804 __CFRunLoopRun + 820 (CFRunLoop.c:2951)
19 CoreFoundation 0x000000018365a3c8 CFRunLoopRunSpecific + 600 (CFRunLoop.c:3268)
20 GraphicsServices 0x000000019ee6b38c GSEventRunModal + 164 (GSEvent.c:2200)
21 UIKitCore 0x00000001860000bc -[UIApplication _run] + 1100 (UIApplication.m:3457)
22 UIKitCore 0x0000000185d7dbe8 UIApplicationMain + 2124 (UIApplication.m:5013)
23 MyApp 0x00000001004a5b18 main + 68 (AppDelegate.swift:19)
24 dyld 0x000000010092da24 start + 520 (dyldMain.cpp:876)
Inside applicationWillResignActive I am fetching data from my local Realm and update values in UserDefaults.
class AppDelegate: UIResponder, UIApplicationDelegate {
let provider = Provider()
func applicationWillResignActive(_ application: UIApplication) {
if userDefaults.bool(forKey: UserDefaults.Keys.keyWidgetEnabled) {
provider.updateUserDefaults()
}
}
}
class Provider {
let database = try! Realm()
...
func updateUserDefaults() {
let defaults = UserDefaults(suiteName: "com.MyApp.identifier")
let currentDisplayDate = CalculationsHelper.getUTCSubmitDate()
let predicateHistoryDisplayDate = NSPredicate(format: "type=%# AND currentSubmitDate = %#", keyDBFood, currentDisplayDate.absoluteDate as NSDate)
let data = self.database.objects(History.self).filter(predicateHistoryDisplayDate)
mealTypesDB.allFoodTypes.forEach{ (type) in
let key = "widget-" + type.rawValue
let predicate = NSPredicate(format: "meal=%#", type.rawValue)
let kcal: Int = data.filter(predicate).sum(ofProperty: "kcal")
defaults?.set(kcal, forKey: key)
}
//set the date of the next day to update the button
let currentSubmitDate = CalculationsHelper.getLocalSubmitDate()
defaults?.set(currentSubmitDate, forKey: "widget-submitDate")
defaults?.synchronize()
if #available(iOS 14.0, *) {
WidgetCenter.shared.reloadAllTimelines()
}
}
}
I used to do this for every user every time they sent the app to background, but for a week now I've only done it for the small fraction of users who have my widget installed. But number of crashes almost didn't change so I think that this bug is not related with Realm or UserDefaults.
As far as I can tell from AppStore connect, I've always had this bug, but only with the release of iOS 15 has the number of crashes dramatically increased. I'm not really sure how this can be resolved and what exactly has changed in iOS 15 that could provoke such a dramatic increase number of crashes.
I found this thread https://developer.apple.com/forums/thread/106261 and tried renaming all my images in the project so that the file names match the name in Assets, but that didn't work.
Does anyone have any idea what I can do to at least figure out the cause of the crashes?
I contacted Apple TSI and they told me to check that the object inside the applicationWillResignActive and applicationWillTerminate method is nil. And to my surprise at the moment of calling applicationWillTerminate the object is really nil.
But can anyone explain how this is possible? This object is initialised in didFinishLaunchingWithOptions and I never make it equal to nil during the app life cycle. Is it possible that iOS is trying to terminate the application for some reason (not enough memory, for example) and tries to remove all objects from memory one by one, and when applicationWillTerminate is called, object is already removed from memory and therefore it is nil? But at which point it's allowed to nil out a variable of a running class?
UPDATE:
I got a response from the Apple team and I think it's very interesting. They said that didFinishLaunchingWithOptions will ALWAYS be called before other lifecycle delegates for
the "standard" lifecycle like applicationWillResignActive and
applicationDidEnterBackground. However, that's NOT the case with applicationWillTerminate. The
termination process can occur outside the normal lifecycle flow and, at
least in theory, there's not reason it couldn't occur before
didFinishLaunchingWithOptions is actually called.
So if I have an optional variable in AppDelegate that is initialized inside didFinishLaunchingWithOptions, it can still be nil in applicationWillTerminate. This is what causes some users to crash.
Are you calling applicationWillResignActive yourself? It looks like you call it from AppDelegate.applicationWillTerminate. You should never call the UIAppDelegate methods yourself, that is an anti-pattern. I'm not sure that causes the crash though, but you may want to introduce a separate method which you call from both.
The fact that you are using a custom crash reporter (Sentry, Bugsnag, ...) could be an issue. When your app crashes, Apple's crash reporter can get confused and the reported line you get will be completely wrong.
You can find more details provided by an Apple engineer on this Apple dev forum post. He recommends only using Apple's own crash reporter because third-party crash reporters are tied to your app process and can corrupt the stack trace when they try to get it while your app is crashing which results in a wrong report in Xcode.
I'm seeing an unexplained crash on my iOS app built with SwiftUI. It only affects some users, and I can't manage to reproduce locally.
Here is the stack trace:
Fatal Exception: NSInvalidArgumentException
<_TtGC7SwiftUI41StyleContextSplitViewNavigationControllerVS_19SidebarStyleContext_: 0x110859800>
is pushing the same view controller instance(<_TtGC7SwiftUI41StyleContextSplitViewNavigationControllerVS_14NoStyleContext_: 0x11088a400>)
more than once which is not supported and is most likely an error in the application : `com.myapp`
Fatal Exception: NSInvalidArgumentException
0 CoreFoundation 0x1893a186c __exceptionPreprocess
1 libobjc.A.dylib 0x19e3bcc50 objc_exception_throw
2 UIKitCore 0x18b575514 -[UINavigationController pushViewController:transition:forceImmediate:]
3 UIKitCore 0x18b5751f4 -[UINavigationController pushViewController:animated:]
4 UIKitCore 0x18b6047c8 __45-[UISplitViewControllerPanelImpl showColumn:]_block_invoke
5 UIKitCore 0x18b57eda8 -[UINavigationController _executeSplitViewControllerActions:]
6 UIKitCore 0x18b6045bc -[UISplitViewControllerPanelImpl showColumn:]
7 UIKitCore 0x18b5e4c54 -[UISplitViewController showColumn:]
8 SwiftUI 0x1903784f4 closure #1 in closure #1 in NavigationBridge_PhoneTV.push(_:onto:animated:)
9 SwiftUI 0x19042728c thunk for #escaping #callee_guaranteed () -> ()
10 UIKitCore 0x18c23f544 -[_UIAfterCACommitBlock run]
11 UIKitCore 0x18bd6700c _runAfterCACommitDeferredBlocks
12 UIKitCore 0x18bd559a0 _cleanUpAfterCAFlushAndRunDeferredBlocks
13 UIKitCore 0x18bd89bb4 _afterCACommitHandler
14 CoreFoundation 0x18931c358 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__
15 CoreFoundation 0x1893165c4 __CFRunLoopDoObservers
16 CoreFoundation 0x189316b74 __CFRunLoopRun
17 CoreFoundation 0x18931621c CFRunLoopRunSpecific
18 GraphicsServices 0x1a0ee2784 GSEventRunModal
19 UIKitCore 0x18bd56ee8 -[UIApplication _run]
20 UIKitCore 0x18bd5c75c UIApplicationMain
21 MYAPP 0x100dbecc0 main + 7 (PushupsMode.swift:7)
22 libdyld.dylib 0x188fd66b0 start
Looking at PushupsMode.swift:7 it seems completely unrelated:
import Foundation
extension WorkoutModel {
mutating func startPushups() {
var pushupsCount = 10 + p.intensityOptionPicked * 10
if(round > 6 || round < 3) { // <<--- this is the line crashing
pushupsCount = Int(pushupsCount / 2)
}
// More code after that point
}
}
The round variable is defined in another file, but there's nothing really significant around it:
import Foundation
import SwiftUI
struct WorkoutModel: Identifiable {
// bunch of stuff before
var round: Int = -1
// bunch of stuff after
}
Obviously looking at the error message, it seems like something is getting pushed twice... however since I'm using SwiftUI I'm not entirely sure how I could have even done that.
Any pointers would be appreciated!
Your problem may be that you are defining pushupsCount as an Int( on PushupsMode.swift:8 which is causing the exception on :7 from :8 failing pre-execution. Try defining it as pushupsCount = Int pushupsCount / 2 .
Using pushViewController:transition:forceImmediate is not a good idea because pushViewController:animated will be calling on this undocumented method. Rather than changing transition this way you can use other documented methods for changing animation. This thread might be helpful for you. You will also need to add guard in pushViewController:animated and will also need to set transition.duration. Calling pushViewController again and again is perhaps causing crash of app.
This problem is caused when you place your navigationLink inside of a List with observed data.
How to fix :
Remove NavigationLink from inside of the list and place it outside.
I've been struggling with a very weird crash that should not happen at all. I receive the crash report via Hockeyapp, it keeps reporting a crash in a line that the app should not crash at all. I've been facing this problem for already 1 week.
This is the crash report
0 TeacherBox 0x00000001000864f0 TeacherBox.RequestLessonViewController.loadExistingRequests () -> () (RequestLessonViewController.swift:755)
1 TeacherBox 0x0000000100086514 #objc TeacherBox.RequestLessonViewController.loadExistingRequests () -> () (RequestLessonViewController.swift:0)
2 TeacherBox 0x0000000100086a84 function signature specialization <Arg[0] = Dead> of TeacherBox.RequestLessonViewController.viewDidAppear (Swift.Bool) -> () (RequestLessonViewController.swift:122)
3 TeacherBox 0x000000010007e570 #objc TeacherBox.RequestLessonViewController.viewDidAppear (Swift.Bool) -> () (RequestLessonViewController.swift:0)
4 UIKit 0x00000001895b84dc -[UIViewController _setViewAppearState:isAnimating:] + 844
5 UIKit 0x00000001895b8a40 -[UIViewController _endAppearanceTransition:] + 216
6 UIKit 0x0000000189671038 -[UINavigationController navigationTransitionView:didEndTransition:fromView:toView:] + 1232
7 UIKit 0x0000000189742198 __49-[UINavigationController _startCustomTransition:]_block_invoke + 228
8 UIKit 0x00000001896c7cc4 -[_UIViewControllerTransitionContext completeTransition:] + 112
9 UIKit 0x00000001898181ec __53-[_UINavigationParallaxTransition animateTransition:]_block_invoke.97 + 708
10 UIKit 0x00000001895d9214 -[UIViewAnimationBlockDelegate _didEndBlockAnimation:finished:context:] + 488
11 UIKit 0x00000001895d8d38 -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 308
12 UIKit 0x00000001895d8b78 -[UIViewAnimationState animationDidStop:finished:] + 156
Lines of code:
if let booking = rescheduleBooking where booking.confirmed! == 0 {
existingRequests.append(booking)
}
The line 755 is the if statement. In a "if, let, where" statement in swift, "let" checks for the existence of rescheduleBooking, if it exists and is assigned, the where statements is executed.... Am I right?... Anyway, I tested locally in my device and simulator and it doesn't crash there, no matter the values of the vars... it is happening in a different device that I don't have on hands..
Please, if you have any advice, or maybe, if I didn't understand correctly the "if, let where" clause, I will be very grateful of your help and comments.
Thanks..
Your Understanding of "if-let where" clause is correct, but you have to have in mind that if let booking = rescheduleBooking makes sure that rescheduleBooking is not nil and then assigns it to booking. Now even though booking is not nil that does not guarantee that booking.confirmed won't be nil so if it's nil and you force unwrap it it will cause a crash.
You can add another let to make sure booking.confirmed is not nil:
if let booking = rescheduleBooking, let bookingConfirmed = booking.confirmed where bookingConfirmed == 0 {
existingRequests.append(booking)
}
I'm having an exception in my didSelectRowAtIndexPath method and i'm not quite sure why. I'm showing the user a list of possibilities they can select from, the UITableView is populated based on values stored in Core Data. The currently selected item has a Checkmark indicator. My method is below:
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
tableView.deselectRowAtIndexPath(indexPath, animated: true)
let value = self.fetchedResultsController.objectAtIndexPath(indexPath) as CoreDataObject
currentSelected = value.id as Int
self.tableView.reloadData()
}
In development mode it's fine, but in production and testflight it crashes in this method. The crash log is below:
Crashed Thread 0 :
0 CoreFoundation 0x25f41a7d _CFRetain + 165
1 UIKit 0x29619d67 -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] + 919
2 UIKit 0x296cb9df -[UITableView _userSelectRowAtPendingSelectionIndexPath:] + 195
3 UIKit 0x2957da25 _applyBlockToCFArrayCopiedToStack + 309
4 UIKit 0x294f982b _afterCACommitHandler + 459
5 CoreFoundation 0x26007d95 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 21
6 CoreFoundation 0x26005453 __CFRunLoopDoObservers + 279
7 CoreFoundation 0x2600585b __CFRunLoopRun + 915
8 CoreFoundation 0x25f533c1 CFRunLoopRunSpecific + 477
9 CoreFoundation 0x25f531d3 CFRunLoopRunInMode + 107
10 GraphicsServices 0x2d3510a9 GSEventRunModal + 137
11 UIKit 0x29562fa1 UIApplicationMain + 1441
Is there anything i'm missing here? Why is this method crashing? I'm simply storing the currently selected ID and then reloading data so that it can show a checkmark after the reload. Is there something i'm missing here? It should be as simple as just getting the new id and then reloading the data.
The CoreDataObject that i'm using is from Objective-C and the id field is an NSNumber.
I tried other solutions below:
Crash when calling selectRowAtIndexPath:animated:scrollPosition:
iphone app crash at -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:]
iOS - didSelectRowAtIndexPath causes crash in app
In case anybody else has this issue. currentSelected was a global variable declared as Int and the value object has an id field thats `NSNumber. I changed it to the below and it works:
self.currentSelected = value.id.integerValue
I understand about NSObjectInaccessbileExceptions in general, and the need to avoid attempting to fault in an object that has been deleted in another managed context/thread.
However, in my user crash reports, I'm seeing an NSObjectInaccessibleException while merging/saving a child NSManagedObjectContext from a background thread (B) into my main context (A), which seems like an unusual scenario.
The only situation I can imagine that could cause such a thing is the following:
change property of object in thread/context (B)
delete object in thread/context A
save context A
save context B
merge A into B and save A -> exception raised because object doesn't exist in A.
Has anybody else seen an exception in while saving the context like this? I tried to reproduce this manually, but failed. Is there some other scenario where this could happen, and are there any tips for dealing with such?
Thanks!
Fatal Exception
NSObjectInaccessibleException
CoreData could not fulfill a fault for '0x1f019da0 <x-coredata://741E65A8-C211-470E-8194-3005F0DFA71C/TrackInfo/p265>'
0 CoreFoundation __exceptionPreprocess + 162
1 libobjc.A.dylib objc_exception_throw + 30
2 CoreData _PFFaultHandlerLookupRow + 1482
3 CoreData -[NSFaultHandler fulfillFault:withContext:] + 24
4 CoreData -[NSManagedObject(_NSInternalMethods) _updateFromRefreshSnapshot:includingTransients:] + 236
5 CoreData -[NSManagedObjectContext(_NestedContextSupport) _copyChildObject:toParentObject:fromChildContext:] + 96
6 CoreData -[NSManagedObjectContext(_NestedContextSupport) _parentProcessSaveRequest:inContext:error:] + 918
7 CoreData __82-[NSManagedObjectContext(_NestedContextSupport) executeRequest:withContext:error:]_block_invoke_0 + 564
8 libdispatch.dylib _dispatch_barrier_sync_f_slow_invoke + 96
9 libdispatch.dylib _dispatch_client_callout + 22
10 libdispatch.dylib _dispatch_main_queue_callback_4CF + 228
11 CoreFoundation __CFRunLoopRun + 1288
12 CoreFoundation CFRunLoopRunSpecific + 356
13 CoreFoundation CFRunLoopRunInMode + 104
14 GraphicsServices GSEventRunModal + 74
15 UIKit UIApplicationMain + 1120
16 app main.m line 13 main
17 app start
You may try using the following line while you are creating your child context:
privateManagedObjectContext.mergePolicy = NSMergeByPropertyStoreTrumpMergePolicy