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)
Related
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
I've got crash logs for my app from App Store. I'm not able to reproduce the crash and having a hard time deciphering it.
Following is the log -
Incident Identifier: AEF0FFDD-77E4-460F-97E4-B97A32EAE36D
CrashReporter Key: 78177aeeda1175c67f4467d02c023a2a165d1a01
Hardware Model: iPhone7,1
Process: Visits [4558]
Path: /private/var/containers/Bundle/Application/81AC75BC-433C-43E7-887D-8FC6BF5B5703/Visits.app/Visits
Identifier: com.x.y
Version: 1.1.1 (1.1.1)
Code Type: ARM-64 (Native)
Role: Foreground
Parent Process: launchd [1]
Coalition: com.x.y [1143]
Date/Time: 2018-07-20 22:30:36.6608 +0530
Launch Time: 2018-07-20 22:30:35.9017 +0530
OS Version: iPhone OS 11.4.1 (15G77)
Baseband Version: 6.80.00
Report Version: 104
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note: EXC_CORPSE_NOTIFY
Triggered by Thread: 0
Last Exception Backtrace:
0 CoreFoundation 0x184136d8c __exceptionPreprocess + 228 (NSException.m:166)
1 libobjc.A.dylib 0x1832f05ec objc_exception_throw + 56 (objc-exception.mm:521)
2 CoreFoundation 0x1840cfd80 -[__NSSingleObjectArrayI objectAtIndex:] + 128 (NSSingleObjectArray.m:16)
3 UIKit 0x18e6b0aa8 -[UITableViewDataSource tableView:cellForRowAtIndexPath:] + 172 (UITableViewDataSource.m:170)
4 UIKit 0x18e3c90f4 -[UITableViewController tableView:cellForRowAtIndexPath:] + 68 (UITableViewController.m:441)
5 UIKit 0x18de130cc -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 668 (UITableView.m:13463)
6 UIKit 0x18de12d84 -[UITableView _createPreparedCellForGlobalRow:willDisplay:] + 80 (UITableView.m:13514)
7 UIKit 0x18de11aa0 -[UITableView _updateVisibleCellsNow:isRecursive:] + 2280 (UITableView.m:2599)
8 UIKit 0x18de0d5ec -[UITableView layoutSubviews] + 140 (UITableView.m:8565)
9 UIKit 0x18dd4a6f4 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1420 (UIView.m:15239)
10 QuartzCore 0x1882bfe54 -[CALayer layoutSublayers] + 184 (CALayer.mm:9357)
11 QuartzCore 0x1882c3fe4 CA::Layer::layout_if_needed(CA::Transaction*) + 324 (CALayer.mm:9237)
12 UIKit 0x18dd62bf4 -[UIView(Hierarchy) layoutBelowIfNeeded] + 548 (UIView.m:10438)
13 Visits 0x1007a8300 MainViewController.initialSetupForScreen() + 804 (MainViewController.swift:217)
14 Visits 0x1007a7ea4 MainViewController.viewDidLoad() + 924 (MainViewController.swift:175)
15 Visits 0x1007a8838 #objc MainViewController.viewDidLoad() + 28
16 UIKit 0x18dd51e64 -[UIViewController loadViewIfRequired] + 1020 (UIViewController.m:3192)
17 UIKit 0x18dd51a50 -[UIViewController view] + 28 (UIViewController.m:3214)
18 UIKit 0x18dd42ce4 -[UIWindow addRootViewControllerViewIfPossible] + 136 (UIWindow.m:1358)
19 UIKit 0x18dd41b18 -[UIWindow _setHidden:forced:] + 272 (UIWindow.m:1455)
20 UIKit 0x18ddcf62c -[UIWindow makeKeyAndVisible] + 48 (UIWindow.m:4883)
21 UIKit 0x18dd45274 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 3660 (UIApplication.m:2210)
22 UIKit 0x18dd125e0 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1680 (UIApplication.m:3491)
23 UIKit 0x18e342b1c __111-[__UICanvasLifecycleMonitor_Compatability _scheduleFirstCommitForScene:transition:firstActivation:completion:]_block_invoke + 784 (_UICanvasLifecycleMonitor.m:175)
24 UIKit 0x18dd11dd0 +[_UICanvas _enqueuePostSettingUpdateTransactionBlock:] + 160 (_UICanvas.m:591)
25 UIKit 0x18dd11c6c -[__UICanvasLifecycleMonitor_Compatability _scheduleFirstCommitForScene:transition:firstActivation:completion:] + 240 (_UICanvasLifecycleMonitor.m:153)
26 UIKit 0x18dd10afc -[__UICanvasLifecycleMonitor_Compatability activateEventsOnly:withContext:completion:] + 724 (_UICanvasLifecycleMonitor.m:229)
27 UIKit 0x18e9a684c __82-[_UIApplicationCanvas _transitionLifecycleStateWithTransitionContext:completion:]_block_invoke + 296 (_UIApplicationCanvas.m:0)
28 UIKit 0x18dd101ec -[_UIApplicationCanvas _transitionLifecycleStateWithTransitionContext:completion:] + 432 (_UIApplicationCanvas.m:156)
29 UIKit 0x18e78bac8 __125-[_UICanvasLifecycleSettingsDiffAction performActionsForCanvas:withUpdatedScene:settingsDiff:fromSettings:transitionContext:]_block_invoke + 220 (_UICanvasLifecycleSettingsDiffAction.m:211)
30 UIKit 0x18e8d9bf8 _performActionsWithDelayForTransitionContext + 112 (_UICanvasSettingsDiffAction.m:34)
31 UIKit 0x18dd0fc0c -[_UICanvasLifecycleSettingsDiffAction performActionsForCanvas:withUpdatedScene:settingsDiff:fromSettings:transitionContext:] + 248 (_UICanvasLifecycleSettingsDiffAction.m:182)
32 UIKit 0x18dd0f5a8 -[_UICanvas scene:didUpdateWithDiff:transitionContext:completion:] + 368 (_UICanvas.m:517)
33 UIKit 0x18dd0c5e0 -[UIApplication workspace:didCreateScene:withTransitionContext:completion:] + 540 (UIApplication.m:3109)
34 UIKit 0x18dd0c330 -[UIApplicationSceneClientAgent scene:didInitializeWithEvent:completion:] + 364 (UIApplicationSceneClientAgent.m:41)
35 FrontBoardServices 0x186938470 -[FBSSceneImpl _didCreateWithTransitionContext:completion:] + 364 (FBSSceneImpl.m:460)
36 FrontBoardServices 0x186940d6c __56-[FBSWorkspace client:handleCreateScene:withCompletion:]_block_invoke_2 + 224 (FBSWorkspace.m:606)
37 libdispatch.dylib 0x183a28a60 _dispatch_client_callout + 16 (object.m:507)
38 libdispatch.dylib 0x183a30170 _dispatch_block_invoke_direct$VARIANT$mp + 224 (queue.c:3018)
39 FrontBoardServices 0x18696c878 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 36 (FBSSerialQueue.m:164)
40 FrontBoardServices 0x18696c51c -[FBSSerialQueue _performNext] + 404 (FBSSerialQueue.m:196)
41 FrontBoardServices 0x18696cab8 -[FBSSerialQueue _performNextFromRunLoopSource] + 56 (FBSSerialQueue.m:232)
42 CoreFoundation 0x1840df404 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24 (CFRunLoop.c:1982)
43 CoreFoundation 0x1840dec2c __CFRunLoopDoSources0 + 276 (CFRunLoop.c:2017)
44 CoreFoundation 0x1840dc79c __CFRunLoopRun + 1204 (CFRunLoop.c:2920)
45 CoreFoundation 0x183ffcda8 CFRunLoopRunSpecific + 552 (CFRunLoop.c:3245)
46 GraphicsServices 0x185fe2020 GSEventRunModal + 100 (GSEvent.c:2245)
47 UIKit 0x18e01c758 UIApplicationMain + 236 (UIApplication.m:3965)
48 Visits 0x1007a589c main + 56 (Location+CoreDataClass.swift:15)
49 libdyld.dylib 0x183a8dfc0 start + 4
Thread 0 name:
Thread 0 Crashed:
0 libsystem_kernel.dylib 0x0000000183bbd2e0 __pthread_kill + 8
1 libsystem_pthread.dylib 0x0000000183d5e288 pthread_kill$VARIANT$mp + 376 (pthread.c:1484)
2 libsystem_c.dylib 0x0000000183b2bd0c abort + 140 (abort.c:91)
3 libc++abi.dylib 0x00000001832c72c8 abort_message + 132 (abort_message.cpp:75)
4 libc++abi.dylib 0x00000001832c7470 default_terminate_handler() + 304 (cxa_default_handlers.cpp:68)
5 libobjc.A.dylib 0x00000001832f08d4 _objc_terminate() + 124 (objc-exception.mm:657)
6 libc++abi.dylib 0x00000001832e137c std::__terminate(void (*)()) + 16 (cxa_handlers.cpp:66)
7 libc++abi.dylib 0x00000001832e1400 std::terminate() + 84 (cxa_handlers.cpp:97)
8 libdispatch.dylib 0x0000000183a28a74 _dispatch_client_callout + 36 (object.m:510)
9 libdispatch.dylib 0x0000000183a30170 _dispatch_block_invoke_direct$VARIANT$mp + 224 (queue.c:3018)
10 FrontBoardServices 0x000000018696c878 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 36 (FBSSerialQueue.m:164)
11 FrontBoardServices 0x000000018696c51c -[FBSSerialQueue _performNext] + 404 (FBSSerialQueue.m:196)
12 FrontBoardServices 0x000000018696cab8 -[FBSSerialQueue _performNextFromRunLoopSource] + 56 (FBSSerialQueue.m:232)
13 CoreFoundation 0x00000001840df404 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24 (CFRunLoop.c:1982)
14 CoreFoundation 0x00000001840dec2c __CFRunLoopDoSources0 + 276 (CFRunLoop.c:2017)
15 CoreFoundation 0x00000001840dc79c __CFRunLoopRun + 1204 (CFRunLoop.c:2920)
16 CoreFoundation 0x0000000183ffcda8 CFRunLoopRunSpecific + 552 (CFRunLoop.c:3245)
17 GraphicsServices 0x0000000185fe2020 GSEventRunModal + 100 (GSEvent.c:2245)
18 UIKit 0x000000018e01c758 UIApplicationMain + 236 (UIApplication.m:3965)
19 Visits 0x00000001007a589c main + 56 (Location+CoreDataClass.swift:15)
20 libdyld.dylib 0x0000000183a8dfc0 start + 4
Following is the code snippet where the program crashes. The crash happens at the self.view.layoutIfNeeded().
func initialSetupForScreen(){
let screenHeight = UIScreen.main.bounds.height
let statusBarHeight = UIApplication.shared.statusBarFrame.height
fullyOpenSheetTop = -(screenHeight - (statusBarHeight * 2))
partiallyOpenSheetTop = -((screenHeight * 0.50) - titleBarHeight)
closedSheetTop = -titleBarHeight
notVisibleSheetTop = 40 //(+40 for iphone X)
fullyOrPartiallyThreshold = (fullyOpenSheetTop + partiallyOpenSheetTop)/2
partiallyOrClosedThreshold = (partiallyOpenSheetTop + closedSheetTop)/2
// set primary & secondary sheet height //(+40 for iphone X) (-40 fixed for iphone X)
primarySheetViewHeightConstraint.constant = -fullyOpenSheetTop
secondarySheetViewHeightConstraint.constant = -fullyOpenSheetTop
// primary sheet is set to fully open state
primarySheetViewTopConstraint.constant = fullyOpenSheetTop
primarySheetCurrentState = .fullyOpen
// secondary sheet is set to not visible state
secondarySheetViewTopConstraint.constant = notVisibleSheetTop
secondarySheetCurrentState = .notVisible
// settings View move it out of screen
settingsViewTopConstraint.constant = notVisibleSheetTop
primarySheetController.configurePrimarySheetContentView()
self.view.layoutIfNeeded()
}
Earlier, I was calling this function inside my viewDidLoad. I thought it was too early to call layoutIfNeeded inside viewDidLoad. So I moved the function to viewWillAppear. However, the crashes still seem to be happening . What am I missing/overseeing?
The crash is happening across very few devices and I'm not able to reproduce it.
Below is the crash report downloaded from iTunes Connect, Apple guys says "We were unable to review your app as it crashed on launch".
i know 'EXC_BREAKPOINT (SIGTRAP)' means a non-optional type with a nil value or a failed forced type conversion, i checked the row 0, 1, 2 and 41 concerned about my app's property, new installed, and try updated from old version, all on real device, everything works fine, no crash happens. i've no idea where is the crash kicked?
it's very helpful you can give some me advice. thank you very much!!!
Exception Type: EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0x0000000000000001, 0x0000000101066d5c
Termination Signal: Trace/BPT trap: 5
Termination Reason: Namespace SIGNAL, Code 0x5
Terminating Process: exc handler [0]
Triggered by Thread: 0
Filtered syslog:
None found
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 Cloud 0x0000000101066d5c specialized static ContentViewController.iphone.getter + 388444 (ContentViewController.swift:20)
1 Cloud 0x0000000101049584 specialized PageViewController.init(coder:) + 267652 (PageViewController.swift:16)
2 Cloud 0x000000010104657c #objc PageViewController.init(coder:) + 255356 (PageViewController.swift:0)
3 UIKit 0x000000018acee8bc -[UIClassSwapper initWithCoder:] + 248
4 UIKit 0x000000018ae97588 UINibDecoderDecodeObjectForValue + 688
5 UIKit 0x000000018ae972c0 -[UINibDecoder decodeObjectForKey:] + 104
6 UIKit 0x000000018acee560 -[UIRuntimeConnection initWithCoder:] + 188
7 UIKit 0x000000018ae97588 UINibDecoderDecodeObjectForValue + 688
8 UIKit 0x000000018ae97700 UINibDecoderDecodeObjectForValue + 1064
9 UIKit 0x000000018ae972c0 -[UINibDecoder decodeObjectForKey:] + 104
10 UIKit 0x000000018aced8a0 -[UINib instantiateWithOwner:options:] + 1168
11 UIKit 0x000000018b06a7f0 -[UIStoryboard instantiateViewControllerWithIdentifier:] + 196
12 UIKit 0x000000018a9d08dc -[UIApplication _loadMainStoryboardFileNamed:bundle:] + 124
13 UIKit 0x000000018a7d6cdc -[UIApplication _loadMainInterfaceFile] + 264
14 UIKit 0x000000018a9cf5c0 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1420
15 UIKit 0x000000018ac5d454 __111-[__UICanvasLifecycleMonitor_Compatability _scheduleFirstCommitForScene:transition:firstActivation:completion:]_block_invoke + 800
16 UIKit 0x000000018af2d1f0 +[_UICanvas _enqueuePostSettingUpdateTransactionBlock:] + 160
17 UIKit 0x000000018ac5d0b8 -[__UICanvasLifecycleMonitor_Compatability _scheduleFirstCommitForScene:transition:firstActivation:completion:] + 252
18 UIKit 0x000000018ac5d928 -[__UICanvasLifecycleMonitor_Compatability activateEventsOnly:withContext:completion:] + 748
19 UIKit 0x000000018b3c66e8 __82-[_UIApplicationCanvas _transitionLifecycleStateWithTransitionContext:completion:]_block_invoke + 260
20 UIKit 0x000000018b3c658c -[_UIApplicationCanvas _transitionLifecycleStateWithTransitionContext:completion:] + 448
21 UIKit 0x000000018b1429c0 __125-[_UICanvasLifecycleSettingsDiffAction performActionsForCanvas:withUpdatedScene:settingsDiff:fromSettings:transitionContext:]_block_invoke + 220
22 UIKit 0x000000018b2d7fc8 _performActionsWithDelayForTransitionContext + 112
23 UIKit 0x000000018b142870 -[_UICanvasLifecycleSettingsDiffAction performActionsForCanvas:withUpdatedScene:settingsDiff:fromSettings:transitionContext:] + 252
24 UIKit 0x000000018af2c850 -[_UICanvas scene:didUpdateWithDiff:transitionContext:completion:] + 364
25 UIKit 0x000000018a9cde28 -[UIApplication workspace:didCreateScene:withTransitionContext:completion:] + 540
26 UIKit 0x000000018add16ec -[UIApplicationSceneClientAgent scene:didInitializeWithEvent:completion:] + 364
27 FrontBoardServices 0x00000001839f9768 -[FBSSceneImpl _didCreateWithTransitionContext:completion:] + 364
28 FrontBoardServices 0x0000000183a02070 __56-[FBSWorkspace client:handleCreateScene:withCompletion:]_block_invoke_2 + 224
29 libdispatch.dylib 0x0000000180cdd048 _dispatch_client_callout + 16
30 libdispatch.dylib 0x0000000180ce46c8 _dispatch_block_invoke_direct$VARIANT$mp + 288
31 FrontBoardServices 0x0000000183a2da04 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 36
32 FrontBoardServices 0x0000000183a2d6a8 -[FBSSerialQueue _performNext] + 404
33 FrontBoardServices 0x0000000183a2dc44 -[FBSSerialQueue _performNextFromRunLoopSource] + 56
34 CoreFoundation 0x0000000181300358 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
35 CoreFoundation 0x00000001813002d8 __CFRunLoopDoSource0 + 88
36 CoreFoundation 0x00000001812ffb60 __CFRunLoopDoSources0 + 204
37 CoreFoundation 0x00000001812fd738 __CFRunLoopRun + 1048
38 CoreFoundation 0x000000018121e2d8 CFRunLoopRunSpecific + 436
39 GraphicsServices 0x00000001830aff84 GSEventRunModal + 100
40 UIKit 0x000000018a7cb880 UIApplicationMain + 208
41 Cloud 0x0000000101010e04 main + 36356 (SearchTableViewController.swift:13)
42 libdyld.dylib 0x0000000180d4256c start + 4
the following is the code for static ContentViewController.iphone.getter:
defined in common.swift:
enum iPhone: CGFloat {
case iPhoneSE = 568
case iPhone = 667
case iPhonePlus = 736
case iPhoneX = 812
init!(_ rawValue: CGFloat) {
self.init(rawValue: rawValue)
}
}
defined in ContentViewController.swift:
static var iphone: iPhone {
let sceneHeight: CGFloat = UIScreen.main.bounds.height
if iPhone(sceneHeight) == .iPhoneSE {
return .iPhoneSE
} else if iPhone(sceneHeight) == .iPhone {
return .iPhone
} else if iPhone(sceneHeight) == .iPhonePlus {
return .iPhonePlus
} else {
return .iPhoneX
}
}
init!(_ rawValue: CGFloat) {
self.init(rawValue: rawValue) }
You use here force unwrapped init but you have cases where enum can return nil if no cases corresponds with the passed value. It can be iPad (768) or iPhone 4s (480). So you are unwrapping nil and system throws an exception.
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)