I had the error below:
'*** -[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[1]'
it happens when I try to save texts from textfields using saveInBackground or other kind of saving method of Parse. Because code is little, all code is pasted below:
#IBAction func onSave(_ sender: Any) {
let profile = PFObject(className: "Info")
profile["preferredName"] = nameTextField.text!
profile["major"] = majorTextField.text!
profile["introduction"] = bioTextView.text!
let segmentIndex = yearSegmented.selectedSegmentIndex
UserDefaults.standard.set(segmentIndex, forKey: "segmentIndex")
profile["year"] = yearSegmented.titleForSegment(at: segmentIndex)!
print(profile.allKeys) // print keys in profile
print(profile.value(forKey: "introduction")!, profile.value(forKey: "major")!,
profile.value(forKey: "year")!, profile.value(forKey: "preferredName")!) // print values in profile
profile.saveInBackground(block: { (success, error) in // line where the error happens
if success {
UserDefaults.standard.set(true, forKey: "hasProfile")
print("profile saved")
} else {
print("failed to save profile")
}
})
This is how Parse IOS Guide told me about how to save objects:
let gameScore = PFObject(className:"GameScore")
gameScore["score"] = 1337
gameScore["playerName"] = "Sean Plott"
gameScore["cheatMode"] = false
gameScore.saveInBackground { (succeeded, error) in
if (succeeded) {
// The object has been saved.
} else {
// There was a problem, check error.description
}
}
I tested if any content in profile is nil, but all keys and values are there and can be printed. I don't see anything nil here, so I cannot understand this error. If anyone could shed some light to enlighten me, I would be be very grateful for this.
In case anyone needs the stack trace:
0 CoreFoundation 0x00000001803f25e4 __exceptionPreprocess + 236
1 libobjc.A.dylib 0x000000018019813c objc_exception_throw + 56
2 CoreFoundation 0x00000001804775b4 -[__NSCFString characterAtIndex:].cold.1 + 0
3 CoreFoundation 0x0000000180474fc4 -[__NSPlaceholderArray initWithCapacity:].cold.1 + 0
4 CoreFoundation 0x00000001802ef138 -[__NSPlaceholderArray initWithObjects:count:] + 184
5 CoreFoundation 0x00000001803dddec +[NSArray arrayWithObjects:count:] + 44
6 Parse 0x0000000104eda478 -[PFTaskQueue enqueue:] + 380
7 Parse 0x0000000104e78b2c -[PFObject saveInBackground] + 148
8 Parse 0x0000000104e78c1c -[PFObject saveInBackgroundWithBlock:] + 68
9 StudyMate 0x00000001041c59bc $s9StudyMate18EditViewControllerC6onSaveyyypF + 7276
10 StudyMate 0x00000001041c5fe4 $s9StudyMate18EditViewControllerC6onSaveyyypFTo + 68
11 UIKitCore 0x0000000184d81fa0 -[UIApplication sendAction:to:from:forEvent:] + 96
12 UIKitCore 0x00000001842a7714 -[UIBarButtonItem _triggerActionForEvent:] + 176
13 UIKitCore 0x000000018427fe24 __45-[_UIButtonBarTargetAction _invoke:forEvent:]_block_invoke + 36
14 UIKitCore 0x000000018427fcd8 -[_UIButtonBarTargetAction _invoke:forEvent:] + 168
15 UIKitCore 0x0000000184d81fa0 -[UIApplication sendAction:to:from:forEvent:] + 96
16 UIKitCore 0x0000000184680bd8 -[UIControl sendAction:to:forEvent:] + 124
17 UIKitCore 0x0000000184680fc0 -[UIControl _sendActionsForEvents:withEvent:] + 352
18 UIKitCore 0x0000000184681010 -[UIControl _sendActionsForEvents:withEvent:] + 432
19 UIKitCore 0x000000018467f8e8 -[UIControl touchesEnded:withEvent:] + 516
20 UIKitCore 0x0000000184dc0af0 -[UIWindow _sendTouchesForEvent:] + 1104
21 UIKitCore 0x0000000184dc25d4 -[UIWindow sendEvent:] + 4332
22 UIKitCore 0x0000000184d9a390 -[UIApplication sendEvent:] + 784
23 UIKitCore 0x0000000184e286f4 __dispatchPreprocessedEventFromEventQueue + 7520
24 UIKitCore 0x0000000184e2a770 __processEventQueue + 6764
25 UIKitCore 0x0000000184e22760 __eventFetcherSourceCallback + 184
26 CoreFoundation 0x0000000180360820 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
27 CoreFoundation 0x0000000180360720 __CFRunLoopDoSource0 + 204
28 CoreFoundation 0x000000018035fab0 __CFRunLoopDoSources0 + 256
29 CoreFoundation 0x000000018035a004 __CFRunLoopRun + 744
30 CoreFoundation 0x0000000180359804 CFRunLoopRunSpecific + 572
31 GraphicsServices 0x000000018c23660c GSEventRunModal + 160
32 UIKitCore 0x0000000184d7bd2c -[UIApplication _run] + 992
33 UIKitCore 0x0000000184d808c8 UIApplicationMain + 112
34 libswiftUIKit.dylib 0x00000001b6766224 $s5UIKit17UIApplicationMainys5Int32VAD_SpySpys4Int8VGGSgSSSgAJtF + 100
35 StudyMate 0x00000001041c7a9c $sSo21UIApplicationDelegateP5UIKitE4mainyyFZ + 104
36 StudyMate 0x00000001041c7a24 $s9StudyMate11AppDelegateC5$mainyyFZ + 44
37 StudyMate 0x00000001041c7b20 main + 28
38 dyld 0x0000000104501cd8 start_sim + 20
39 ??? 0x0000000104451088 0x0 + 4366602376
40 ??? 0xb23a000000000000 0x0 + 12842577287400390656
Related
I have an object that stores latitude and longitude coordinates. At one point, they were stored as an Optional Double?. I have since changed so it is a non optional Double. Now I see random crash logs from what I assume is users updating their app.
I tried checking to make sure that there is a value there, but it is still causing the crash.
let lat: Double
...
required init (coder aDecoder: NSCoder) {
...
if aDecoder.containsValue(forKey: "lat") {
lat = aDecoder.decodeDouble(forKey: "lat") //here is the crash
}else{
lat = 0
}
...
}
I previously came across this issue and used the following code to get around it, but Xcode says I cannot decode Doubles from objects any more
if let v = aDecoder.decodeObject(forKey: "lat") as? Double{//*** -[NSKeyedUnarchiver decodeObjectForKey:] : value for key ( lat ) is not an object. This will become an error in the future.
lat = v
}else{
if aDecoder.containsValue(forKey: "lat") {
lat = aDecoder.decodeDouble(forKey: "lat")
}else{
lat = 0
}
}
Here is a crash log:
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note: EXC_CORPSE_NOTIFY
Triggered by Thread: 0
Last Exception Backtrace:
0 CoreFoundation 0x18120004c __exceptionPreprocess + 220 (NSException.m:200)
1 libobjc.A.dylib 0x199874f54 objc_exception_throw + 60 (objc-exception.mm:565)
2 Foundation 0x182aa8e68 -[NSCoder __failWithException:] + 180 (NSCoder.m:0)
3 Foundation 0x182aa8fd4 -[NSCoder(Exceptions) __failWithExceptionName:errorCode:format:] + 260 (NSCoder.m:1191)
4 Foundation 0x182a4689c _decodeDouble + 660 (NSKeyedArchiver.m:0)
5 Foundation 0x1829bd3cc -[NSKeyedUnarchiver decodeDoubleForKey:] + 172 (NSKeyedArchiver.m:3918)
6 *Project* 0x102eefb98 specialized Location.init(coder:) + 1936 (Location.swift:145)
7 *Project* 0x102eed854 init + 4 (<compiler-generated>:0)
8 *Project* 0x102eed854 #objc Location.init(coder:) + 32
9 Foundation 0x1829c0268 _decodeObjectBinary + 2560 (NSKeyedArchiver.m:3058)
10 Foundation 0x1829a4a78 _decodeObject + 180 (NSKeyedArchiver.m:3324)
11 Foundation 0x1829c4304 -[NSKeyedUnarchiver decodeObjectForKey:] + 176 (NSKeyedArchiver.m:3344)
12 Foundation 0x182a272b8 +[NSKeyedUnarchiver unarchiveObjectWithData:] + 84 (NSKeyedArchiver.m:2390)
13 *Project* 0x102ee729c APS.loadOnDeckFromiCloud() + 240 (APS.swift:138)
14 *Project* 0x102ee7058 APS.().init() + 860 (APS.swift:105)
15 *Project* 0x102ee6ce8 one-time initialization function for SI + 40 (APS.swift:0)
16 libdispatch.dylib 0x180e72660 _dispatch_client_callout + 20 (object.m:560)
17 libdispatch.dylib 0x180e73f08 _dispatch_once_callout + 32 (once.c:52)
18 *Project* 0x102f3417c specialized DivertToOnboardingIfNeeded_VC.viewWillAppear(_:) + 1536 (APS.swift:97)
19 *Project* 0x102f334a8 viewWillAppear + 4 (<compiler-generated>:0)
20 *Project* 0x102f334a8 #objc DivertToOnboardingIfNeeded_VC.viewWillAppear(_:) + 28
21 UIKitCore 0x1837ba3e0 -[UIViewController _setViewAppearState:isAnimating:] + 664 (UIViewController.m:5522)
22 UIKitCore 0x1838e9004 -[UIViewController __viewWillAppear:] + 120 (UIViewController.m:5654)
23 UIKitCore 0x1838ba5b0 -[UINavigationController _startTransition:fromViewController:toViewController:] + 720 (UINavigationController.m:7329)
24 UIKitCore 0x183ae657c -[UINavigationController _startDeferredTransitionIfNeeded:] + 876 (UINavigationController.m:7494)
25 UIKitCore 0x1839bb6ac -[UINavigationController __viewWillLayoutSubviews] + 168 (UINavigationController.m:7806)
26 UIKitCore 0x1838e20f4 -[UILayoutContainerView layoutSubviews] + 228 (UILayoutContainerView.m:88)
27 UIKitCore 0x18379aed8 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 2620 (UIView.m:18347)
28 QuartzCore 0x184ef6e24 CA::Layer::layout_if_needed(CA::Transaction*) + 536 (CALayer.mm:10038)
29 QuartzCore 0x184ee9644 CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 144 (CALayer.mm:2480)
30 QuartzCore 0x184efdc6c CA::Context::commit_transaction(CA::Transaction*, double, double*) + 524 (CAContextInternal.mm:2586)
31 QuartzCore 0x184f06560 CA::Transaction::commit() + 680 (CATransactionInternal.mm:449)
32 UIKitCore 0x183963f9c __34-[UIApplication _firstCommitBlock]_block_invoke_2 + 44 (UIApplication.m:11470)
33 CoreFoundation 0x1811d9924 __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 28 (CFRunLoop.c:1820)
34 CoreFoundation 0x1811da820 __CFRunLoopDoBlocks + 412 (CFRunLoop.c:1862)
35 CoreFoundation 0x181172808 __CFRunLoopRun + 840 (CFRunLoop.c:2953)
36 CoreFoundation 0x1811863b8 CFRunLoopRunSpecific + 600 (CFRunLoop.c:3268)
37 GraphicsServices 0x19cb1638c GSEventRunModal + 164 (GSEvent.c:2200)
38 UIKitCore 0x183b266a8 -[UIApplication _run] + 1100 (UIApplication.m:3493)
39 UIKitCore 0x1838a57f4 UIApplicationMain + 2092 (UIApplication.m:5046)
40 *Project* 0x102e93388 main + 68 (MapBox_VC.swift:15)
41 dyld 0x103169a24 start + 520 (dyldMain.cpp:876)
How do I check the value stored in lat to make sure it is a Double ? (Non optional)
I have an iOS app that uses Firebase Crashlytics for reporting crashes. Now I have a report for a crash but my problem is that I could not understand what exactly caused the crash from this report.
Crashlytics report:
Crashed: com.apple.main-thread
0 Nail it 0x104db77a8 CaseDetailsViewController.getbaseData() + 253
(CaseDetailsViewController.swift:253)
1 Nail it 0x104db5168 CaseDetailsViewController.viewDidLoad() + 4335047016 (<compiler-generated>:4335047016)
2 Nail it 0x104db521c #objc CaseDetailsViewController.viewDidLoad() + 4335047196 (<compiler-generated>:4335047196)
3 UIKitCore 0x185d11658 -[UIViewController _sendViewDidLoadWithAppearanceProxyObjectTaggingEnabled] + 100
4 UIKitCore 0x185d160e8 -[UIViewController loadViewIfRequired] + 936
5 UIKitCore 0x185d164f0 -[UIViewController view] + 28
6 UIKit 0x1b913374c -[UIViewControllerAccessibility dismissViewControllerWithTransition:completion:] + 268
7 UIKitCore 0x185d28d6c -[UIViewController _performCoordinatedPresentOrDismiss:animated:] + 508
8 UIKitCore 0x185d2b474 -[UIViewController dismissViewControllerAnimated:completion:] + 132
9 UIKit 0x1b91333c0 -[UIViewControllerAccessibility dismissViewControllerAnimated:completion:] + 120
10 Nail it 0x104db98ec #objc CaseDetailsViewController.backButton(_:) + 4335065324 (<compiler-generated>:4335065324)
11 UIKitCore 0x18635a72c -[UIApplication sendAction:to:from:forEvent:] + 96
12 UIKitCore 0x185a05474 __45-[_UIButtonBarTargetAction _invoke:forEvent:]_block_invoke + 80
13 UIKitCore 0x185a05304 -[_UIButtonBarTargetAction _invoke:forEvent:] + 236
14 UIKitCore 0x18635a72c -[UIApplication sendAction:to:from:forEvent:] + 96
15 UIKitCore 0x185d6aed0 -[UIControl sendAction:to:forEvent:] + 240
16 UIKitCore 0x185d6b228 -[UIControl _sendActionsForEvents:withEvent:] + 396
17 UIKitCore 0x185d6a24c -[UIControl touchesEnded:withEvent:] + 516
18 UIKitCore 0x18639449c -[UIWindow _sendTouchesForEvent:] + 1280
19 UIKitCore 0x186395c64 -[UIWindow sendEvent:] + 3468
20 UIKitCore 0x1863718ec -[UIApplication sendEvent:] + 344
21 UIKit 0x1b90db80c -[UIApplicationAccessibility sendEvent:] + 96
22 UIKitCore 0x1863f2970 __dispatchPreprocessedEventFromEventQueue + 6808
23 UIKitCore 0x1863f54ec __handleEventQueueInternal + 5364
24 UIKitCore 0x1863ed168 __handleHIDEventFetcherDrain + 140
25 CoreFoundation 0x182223ad8 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
26 CoreFoundation 0x182223a30 __CFRunLoopDoSource0 + 80
27 CoreFoundation 0x1822231b8 __CFRunLoopDoSources0 + 184
28 CoreFoundation 0x18221e1e8 __CFRunLoopRun + 788
29 CoreFoundation 0x18221dba8 CFRunLoopRunSpecific + 424
30 GraphicsServices 0x18c394344 GSEventRunModal + 160
31 UIKitCore 0x1863593e4 UIApplicationMain + 1932
32 Nail it 0x104d797cc main + 16 (AppDelegate.swift:16)
33 libdyld.dylib 0x1820a58f0 start + 4
Below is the function getBaseData() from CasesDetails View Controller:
func getbaseData(){
let userDefaults = UserDefaults.standard
mobile = userDefaults.value(forKey: "mobile") as! String
altenativeMobile = userDefaults.string(forKey: "altenativeMobile") ?? mobile
privateKey = userDefaults.value(forKey: "privateKey") as! String
////reading JSON
let categoriesJsonString = userDefaults.value(forKey: "categoriesString") as! String
let data = categoriesJsonString.data(using: .utf8)!
if let json = try? JSON(data: data) {
let arrayCats = json["content"][1]["caseMappings"][caseCategoryGlobal].array
if(isNoSubsGlob == 0){
if let arrayCatsCount = arrayCats?.count {
print("The array has been created with \(arrayCatsCount) element")
print("sub1Glob= \(sub1Glob) & sub2Glob= \(sub2Glob)")
for var i in 0..<arrayCatsCount{
let sub1 = json["content"][1]["caseMappings"][caseCategoryGlobal][i]["sub1"].string!
let sub2 = json["content"][1]["caseMappings"][caseCategoryGlobal][i]["sub2"].string ?? ""
if (sub1 == sub1Glob && sub2 == sub2Glob){
departmentId = json["content"][1]["caseMappings"][caseCategoryGlobal][i]["departmentId"].int!
WorkTypeId = json["content"][1]["caseMappings"][caseCategoryGlobal][i]["categoryId"].int!
issueCode = json["content"][1]["caseMappings"][caseCategoryGlobal][i]["id"].int!
}
}
}
}else{
departmentId = json["content"][1]["caseMappings"][caseCategoryGlobal][0]["departmentId"].int!
WorkTypeId = json["content"][1]["caseMappings"][caseCategoryGlobal][0]["categoryId"].int!
issueCode = json["content"][1]["caseMappings"][caseCategoryGlobal][0]["id"].int!
}
}
contactNumberText.text = altenativeMobile
}
and the line 235 is (contactNumberText.text = altenativeMobile) as the last line in the code above
All UI stuff should be performed on main thread, that is what your crash report shows (crash due to main thread.)
So your last line should be :
DispatchQueue.main.async {
self.contactNumberText.text = altenativeMobile
}
Update this line, your crash will fixed.
I'm trying to figure out why I cannot check for nil on the following function call:
var allExercises : Results<Exercises>?
var exerciseIndex : Int = 0
#objc func goToNextExercise(){
if allExercises?[exerciseIndex] != nil {
print("Does not equal nil")
exerciseIndex += 1
} else {
print("Does equal nil")
}
}
When allExercises?[exerciseIndex] does equal nil, the application crashes and I get an "indexPath out of Range" error:
*** Terminating app due to uncaught exception 'RLMException', reason: 'Index 3 is out of bounds (must be less than 3).'
*** First throw call stack:
(
0 CoreFoundation 0x0000000104a7127e __exceptionPreprocess + 350
1 libobjc.A.dylib 0x00000001048deb20 objc_exception_throw + 48
2 SectionRowsTutorial 0x00000001025d7aae _Z20RLMThrowResultsErrorP8NSString + 670
3 SectionRowsTutorial 0x00000001025d8cc6 _ZL25translateRLMResultsErrorsIZ28-[RLMResults objectAtIndex:]E3$_6EDaOT_P8NSString + 118
4 SectionRowsTutorial 0x00000001025d8bf4 -[RLMResults objectAtIndex:] + 100
5 SectionRowsTutorial 0x000000010278c9dc $s10RealmSwift7ResultsVyxSicig + 236
6 SectionRowsTutorial 0x00000001022dc576 $s19SectionRowsTutorial19ThirdViewControllerC16goToNextExerciseyyF + 246
7 SectionRowsTutorial 0x00000001022dc87b $s19SectionRowsTutorial19ThirdViewControllerC16goToNextExerciseyyFTo + 43
8 UIKitCore 0x0000000108571fff -[UIApplication sendAction:to:from:forEvent:] + 83
9 UIKitCore 0x0000000107f4a00e -[UIControl sendAction:to:forEvent:] + 223
10 UIKitCore 0x0000000107f4a358 -[UIControl _sendActionsForEvents:withEvent:] + 398
11 UIKitCore 0x0000000107f492b7 -[UIControl touchesEnded:withEvent:] + 481
12 UIKitCore 0x00000001085acbbf -[UIWindow _sendTouchesForEvent:] + 2604
13 UIKitCore 0x00000001085ae4c6 -[UIWindow sendEvent:] + 4596
14 UIKitCore 0x000000010858953b -[UIApplication sendEvent:] + 356
15 UIKitCore 0x000000010860a71a __dispatchPreprocessedEventFromEventQueue + 6847
16 UIKitCore 0x000000010860d1e0 __handleEventQueueInternal + 5980
17 CoreFoundation 0x00000001049d4471 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
18 CoreFoundation 0x00000001049d439c __CFRunLoopDoSource0 + 76
19 CoreFoundation 0x00000001049d3b74 __CFRunLoopDoSources0 + 180
20 CoreFoundation 0x00000001049ce87f __CFRunLoopRun + 1263
21 CoreFoundation 0x00000001049ce066 CFRunLoopRunSpecific + 438
22 GraphicsServices 0x000000010e756bb0 GSEventRunModal + 65
23 UIKitCore 0x0000000108570d4d UIApplicationMain + 1621
24 SectionRowsTutorial 0x00000001022e759b main + 75
25 libdyld.dylib 0x0000000105ba4c25 start + 1
26 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
You are checking the value of allExercises, if you pass a greater index than the array size, it's crashing. for check, you should first check if exerciseIndex is less than allExercises count - 1 and then check data
if exerciseIndex <= allExercises.count - 1
I cannot implement IN in NSPredicate. I am getting this error. I have checked everything but hasnt been able to resolve this. Has anyone found similar issue?
Here's my model
And Here's the code Im doing
let messageLocalFetchRequest = NSFetchRequest<NSFetchRequestResult>.init(entityName: "Transaction")
messageLocalFetchRequest.predicate = NSPredicate.init(format: "category IN %#", ["Food","Rent"])
let array = try? self.context?.fetch(messageLocalFetchRequest)
Here's complete Log
2017-05-15 19:31:33.985 BudgetApp[26354:184185] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'unimplemented SQL generation for predicate : (category IN {"Food", "Rent"})'
*** First throw call stack:
(
0 CoreFoundation 0x01719ded __exceptionPreprocess + 189
1 libobjc.A.dylib 0x00dfad6f objc_exception_throw + 49
2 CoreData 0x0138266e -[NSSQLGenerator newSQLStatementForRequest:ignoreInheritance:countOnly:nestingLevel:nestIsWhereScoped:requestContext:] + 1710
3 CoreData 0x013826b1 -[NSSQLGenerator newSQLStatementForFetchRequest:ignoreInheritance:countOnly:nestingLevel:nestIsWhereScoped:requestContext:] + 49
4 CoreData 0x0138c1ce -[NSSQLiteAdapter _statementForFetchRequestContext:ignoreInheritance:countOnly:nestingLevel:] + 206
5 CoreData 0x0126256e -[NSSQLiteAdapter newSelectStatementWithFetchRequestContext:ignoreInheritance:] + 158
6 CoreData 0x013b91cb -[NSSQLFetchRequestContext _createStatement] + 75
7 CoreData 0x013b913d -[NSSQLFetchRequestContext fetchStatement] + 45
8 CoreData 0x013ba540 -[NSSQLFetchRequestContext executeRequestUsingConnection:] + 64
9 CoreData 0x013e76d3 __52-[NSSQLDefaultConnectionManager handleStoreRequest:]_block_invoke + 275
10 libdispatch.dylib 0x05473cc9 _dispatch_client_callout + 14
11 libdispatch.dylib 0x0544fac4 _dispatch_barrier_sync_f_invoke + 180
12 libdispatch.dylib 0x0544f82b dispatch_barrier_sync_f + 157
13 libdispatch.dylib 0x0544fbb8 dispatch_sync + 41
14 CoreData 0x013e7571 -[NSSQLDefaultConnectionManager handleStoreRequest:] + 241
15 CoreData 0x013eec7a -[NSSQLCoreDispatchManager routeStoreRequest:] + 282
16 CoreData 0x0136e645 -[NSSQLCore dispatchRequest:withRetries:] + 213
17 CoreData 0x0136b421 -[NSSQLCore processFetchRequest:inContext:] + 113
18 CoreData 0x01261b31 -[NSSQLCore executeRequest:withContext:error:] + 465
19 CoreData 0x01354481 __65-[NSPersistentStoreCoordinator executeRequest:withContext:error:]_block_invoke + 2769
20 CoreData 0x0134c3e5 -[NSPersistentStoreCoordinator _routeHeavyweightBlock:] + 341
21 CoreData 0x01261703 -[NSPersistentStoreCoordinator executeRequest:withContext:error:] + 579
22 CoreData 0x0125fb93 -[NSManagedObjectContext executeFetchRequest:error:] + 675
23 BudgetApp 0x000d0cfb _TFC9BudgetApp30TransactionTableViewController11viewDidLoadfT_T_ + 2059
24 BudgetApp 0x000d1052 _TToFC9BudgetApp30TransactionTableViewController11viewDidLoadfT_T_ + 34
25 UIKit 0x025ef61c -[UIViewController _sendViewDidLoadWithAppearanceProxyObjectTaggingEnabled] + 38
26 UIKit 0x025f3fa5 -[UIViewController loadViewIfRequired] + 1434
27 UIKit 0x026386b4 -[UINavigationController _layoutViewController:] + 52
28 UIKit 0x02638f57 -[UINavigationController _updateScrollViewFromViewController:toViewController:] + 427
29 UIKit 0x026390e6 -[UINavigationController _startTransition:fromViewController:toViewController:] + 123
30 UIKit 0x0263a26d -[UINavigationController _startDeferredTransitionIfNeeded:] + 979
31 UIKit 0x0263b698 -[UINavigationController __viewWillLayoutSubviews] + 70
32 UIKit 0x02852fd9 -[UILayoutContainerView layoutSubviews] + 235
33 UIKit 0x024fdb23 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1418
34 libobjc.A.dylib 0x00e101d9 -[NSObject performSelector:withObject:] + 59
35 QuartzCore 0x022b50ea -[CALayer layoutSublayers] + 141
36 QuartzCore 0x022a8486 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 398
37 QuartzCore 0x022a82e3 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 21
38 QuartzCore 0x02234a92 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 334
39 QuartzCore 0x02261f8f _ZN2CA11Transaction6commitEv + 483
40 QuartzCore 0x02263b60 _ZN2CA11Transaction17flush_transactionEv + 38
41 UIKit 0x024233a7 _UIApplicationFlushRunLoopCATransactionIfTooLate + 182
42 UIKit 0x02cbe95e __handleEventQueue + 2054
43 UIKit 0x02cbfba3 __handleHIDEventFetcherDrain + 66
44 CoreFoundation 0x016bea5f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
45 CoreFoundation 0x016a41c4 __CFRunLoopDoSources0 + 500
46 CoreFoundation 0x016a369c __CFRunLoopRun + 1084
47 CoreFoundation 0x016a2fd4 CFRunLoopRunSpecific + 372
48 CoreFoundation 0x016a2e4b CFRunLoopRunInMode + 123
49 GraphicsServices 0x070f7a7a GSEventRunModal + 71
50 GraphicsServices 0x070f795f GSEventRun + 80
51 UIKit 0x0242acb9 UIApplicationMain + 148
52 BudgetApp 0x000bc59b main + 75
53 libdyld.dylib 0x054ae779 start + 1
54 ??? 0x00000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
String is object, so you can't just use IN:
Objective-C
[NSPredicate predicateWithFormat:#"ANY %# LIKE[cd] category", #[#"Food",#"Rent"]]
Swift 3.1
NSPredicate(format: "ANY %# LIKE[cd] category", ["Food", "Rent"])
I'm getting these crash reports from XCode (I pasted one at the bottom) and I can't reproduce the error or figure out what the problem is.
From the backtrace I'm thinking it could be related to the decodeObject stuff… I did have some problems with the new decodeBool and decodeDouble functions, so to be sure I made an NSCoder extension:
func safeDecodeDouble(key: String) -> Double? {
if self.containsValue(forKey: key) {
if let value = self.decodeObject(forKey: key) as? Double {
return value
}
return self.decodeDouble(forKey: key)
}
return nil
}
func safeDecodeBool(key: String) -> Bool? {
if self.containsValue(forKey: key) {
if let value = self.decodeObject(forKey: key) as? Bool {
return value
}
return self.decodeBool(forKey: key)
}
return nil
}
func safeDecodeDate(key: String) -> Date? {
if self.containsValue(forKey: key) {
if let value = self.decodeObject(forKey: key) as? Date {
return value
}
}
return nil
}
func safeDecodeString(key: String) -> String? {
if self.containsValue(forKey: key) {
if let value = self.decodeObject(forKey: key) as? String {
return value
}
}
return nil
}
Now I only use the safeDecode functions in my code, but I'm still getting those same crash reports.
The third item in the backtrace says [UIStoryboard storyboardWithName:bundle:], but I don't know what that could have to do with anything. Also every crash report has something about state restoration and decodeObject, so I'm thinking the problem isn't the storyboard instantiation per se.
At the same time I never have any problems when I test state restoration on the simulator or on my devices, so apparently it's only happening to some people.
Any ideas on what could be going on here?
Last Exception Backtrace:
0 CoreFoundation 0x18a146fd8 __exceptionPreprocess + 124 (NSException.m:165)
1 libobjc.A.dylib 0x188ba8538 objc_exception_throw + 56 (objc-exception.mm:521)
2 UIKit 0x190a36850 +[UIStoryboard storyboardWithName:bundle:] + 776 (UIStoryboard.m:99)
3 UIKit 0x190bfacfc -[_UIStoryboardProxy initWithCoder:] + 192 (UIStateRestorationSupport.m:324)
4 Foundation 0x18ab96420 _decodeObjectBinary + 2076 (NSKeyedArchiver.m:2304)
5 Foundation 0x18ab95b58 _decodeObject + 308 (NSKeyedArchiver.m:2467)
6 UIKit 0x1903e62ec -[UIStateRestorationKeyedUnarchiver decodeObjectForKey:] + 88 (UIStateRestorationSupport.m:454)
7 UIKit 0x1903e5ba8 -[UIApplication(StateRestoration) _restoreApplicationPreservationStateWithSessionIdentifier:beginHandler:completionHandler:] + 4772 (UIApplication.m:13551)
8 UIKit 0x1902e76b4 -[UIApplication(StateRestoration) _doRestorationIfNecessary] + 244 (UIApplication.m:13979)
9 UIKit 0x1902e7288 -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 296 (UIApplication.m:1792)
10 UIKit 0x1904f3800 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 3452 (UIApplication.m:2129)
11 UIKit 0x1904f92a8 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1684 (UIApplication.m:3625)
12 UIKit 0x19050dde0 __84-[UIApplication _handleApplicationActivationWithScene:transitionContext:completion:]_block_invoke.3151 + 48 (UIApplication.m:10365)
13 UIKit 0x1904f653c -[UIApplication workspaceDidEndTransaction:] + 168 (UIApplication.m:2990)
14 FrontBoardServices 0x18bcef884 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 36 (FBSSerialQueue.m:158)
15 FrontBoardServices 0x18bcef6f0 -[FBSSerialQueue _performNext] + 176 (FBSSerialQueue.m:177)
16 FrontBoardServices 0x18bcefaa0 -[FBSSerialQueue _performNextFromRunLoopSource] + 56 (FBSSerialQueue.m:206)
17 CoreFoundation 0x18a0f5424 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24 (CFRunLoop.c:1943)
18 CoreFoundation 0x18a0f4d94 __CFRunLoopDoSources0 + 540 (CFRunLoop.c:1989)
19 CoreFoundation 0x18a0f29a0 __CFRunLoopRun + 744 (CFRunLoop.c:2821)
20 CoreFoundation 0x18a022d94 CFRunLoopRunSpecific + 424 (CFRunLoop.c:3113)
21 UIKit 0x1902e045c -[UIApplication _run] + 652 (UIApplication.m:2658)
22 UIKit 0x1902db130 UIApplicationMain + 208 (UIApplication.m:4089)
23 Leio 0x1000b6ecc main + 120 (BookInfoTableViewController.swift:19)
24 libdyld.dylib 0x18903159c start + 4
Edit: Here's a different crash report that showed up and suggests there really is a problem with state restoration. I can never reproduce it myself, though. :/
0 CoreFoundation 0x18385adb0 __exceptionPreprocess + 124 (NSException.m:162)
1 libobjc.A.dylib 0x182ebff80 objc_exception_throw + 56 (objc-exception.mm:531)
2 Foundation 0x1841d4704 -[NSCoder(Exceptions) __failWithException:] + 132 (NSCoder.m:544)
3 Foundation 0x1841d48bc -[NSCoder(Exceptions) __failWithExceptionName:errorCode:format:] + 440 (NSCoder.m:580)
4 Foundation 0x1841a33b8 _decodeObjectBinary + 2996 (NSKeyedArchiver.m:2173)
5 Foundation 0x1841a274c _decodeObject + 304 (NSKeyedArchiver.m:2313)
6 UIKit 0x188b3e20c -[UIStateRestorationKeyedUnarchiver decodeObjectForKey:] + 88 (UIStateRestorationSupport.m:454)
7 UIKit 0x188b3daf8 -[UIApplication(StateRestoration) _restoreApplicationPreservationStateWithSessionIdentifier:beginHandler:completionHandler:] + 4908 (UIApplication.m:15043)
8 UIKit 0x188a32d44 -[UIApplication(StateRestoration) _doRestorationIfNecessary] + 244 (UIApplication.m:15471)
9 UIKit 0x188a32964 -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 308 (UIApplication.m:1860)
10 UIKit 0x188c62184 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 2904 (UIApplication.m:2112)
11 UIKit 0x188c665f0 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1684 (UIApplication.m:3355)
12 UIKit 0x188c63764 -[UIApplication workspaceDidEndTransaction:] + 168 (UIApplication.m:2748)
13 FrontBoardServices 0x1851fb7ac __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 36 (FBSSerialQueue.m:158)
14 FrontBoardServices 0x1851fb618 -[FBSSerialQueue _performNext] + 168 (FBSSerialQueue.m:177)
15 FrontBoardServices 0x1851fb9c8 -[FBSSerialQueue _performNextFromRunLoopSource] + 56 (FBSSerialQueue.m:206)
16 CoreFoundation 0x18381109c __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24 (CFRunLoop.c:1761)
17 CoreFoundation 0x183810b30 __CFRunLoopDoSources0 + 540 (CFRunLoop.c:1807)
18 CoreFoundation 0x18380e830 __CFRunLoopRun + 724 (CFRunLoop.c:2536)
19 CoreFoundation 0x183738c50 CFRunLoopRunSpecific + 384 (CFRunLoop.c:2814)
20 UIKit 0x188a2b94c -[UIApplication _run] + 460 (UIApplication.m:2578)
21 UIKit 0x188a26088 UIApplicationMain + 204 (UIApplication.m:3772)
22 Leio 0x1000f6ecc main + 120 (BookInfoTableViewController.swift:19)
23 libdyld.dylib 0x1832d68b8 start + 4 (start_glue.s:78)