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.
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
There is a strange crash happening in my code related to core location. Tried a lot but Was not able to figure out the reason for the crash.
Here is the stack race of the crash report :-
com.apple.main-thread
0 libsystem_kernel.dylib 0x1f0f53ed0 mach_msg_trap + 8
1 libsystem_kernel.dylib 0x1f0f533a8 mach_msg + 72
2 libxpc.dylib 0x1f102d0c0 xpc_pipe_routine + 388
3 libxpc.dylib 0x1f1012db8 _xpc_interface_routine + 204
4 libxpc.dylib 0x1f1013394 _xpc_look_up_endpoint + 224
5 libxpc.dylib 0x1f1019870 _xpc_connection_bootstrap_look_up_slow + 212
6 libxpc.dylib 0x1f101be64 _xpc_connection_init + 540
7 libxpc.dylib 0x1f101aae8 _xpc_connection_activate_if_needed + 100
8 libxpc.dylib 0x1f101ab7c xpc_connection_resume + 88
9 CoreLocation 0x1f82c9fa4 CLClientCreateIso6709Notation + 45656
10 CoreLocation 0x1f82cbfc8 CLClientCreateIso6709Notation + 53884
11 CoreLocation 0x1f828395c CLClientStopVehicleHeadingUpdates + 32296
12 Quickride 0x104a76964 LocationChangeListener.startLocationListener() (LocationChangeListener.swift:124)
13 Quickride 0x104f8cb0c BaseLiveRideMapViewController.viewWillAppear(_:) (BaseLiveRideMapViewController.swift)
14 Quickride 0x104f8cc40 #objc BaseLiveRideMapViewController.viewWillAppear(_:) (BaseLiveRideMapViewController.swift)
15 UIKitCore 0x21de8b8ec -[UIViewController _setViewAppearState:isAnimating:] + 584
16 UIKitCore 0x21de8bfd0 -[UIViewController __viewWillAppear:] + 140
17 UIKitCore 0x21ddf2dfc -[UINavigationController _startTransition:fromViewController:toViewController:] + 892
18 UIKitCore 0x21ddf3abc -[UINavigationController _startDeferredTransitionIfNeeded:] + 1184
19 UIKitCore 0x21ddf4dbc -[UINavigationController __viewWillLayoutSubviews] + 164
20 UIKitCore 0x21ddd6fac -[UILayoutContainerView layoutSubviews] + 224
21 UIKitCore 0x21e8f2ea4 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1380
22 QuartzCore 0x1f59bac70 -[CALayer layoutSublayers] + 184
23 QuartzCore 0x1f59bfc00 CA::Layer::layout_if_needed(CA::Transaction*) + 324
24 QuartzCore 0x1f591e718 CA::Context::commit_transaction(CA::Transaction*) + 340
25 QuartzCore 0x1f594d04c CA::Transaction::commit() + 608
26 QuartzCore 0x1f594deb4 CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 92
27 CoreFoundation 0x1f13577a8 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 32
28 CoreFoundation 0x1f135243c __CFRunLoopDoObservers + 412
29 CoreFoundation 0x1f13529dc __CFRunLoopRun + 1264
30 CoreFoundation 0x1f13521cc CFRunLoopRunSpecific + 436
31 GraphicsServices 0x1f35c9584 GSEventRunModal + 100
32 UIKitCore 0x21e44d054 UIApplicationMain + 212
33 Quickride 0x1049b168c main (AppDelegate.swift:29)
34 libdyld.dylib 0x1f0e12bb4 start + 4
The code where the crash is happening is :-
func startLocationListener(){
AppDelegate.getAppDelegate().log.debug("startLocationListener()")
let ridePreferences = UserDataCache.getInstance()?.getLoggedInUserRidePreferences()
if ridePreferences?.locationUpdateAccuracy == 0{
return
}
UIDevice.current.isBatteryMonitoringEnabled = true
if UIDevice.current.batteryLevel > 0 && UIDevice.current.batteryLevel < 0.15{
AppDelegate.getAppDelegate().log.debug("Battery level is less so not starting location updates")
return
}
self.locationManager = CLLocationManager()
locationManager!.requestWhenInUseAuthorization()
self.locationManager!.desiredAccuracy = kCLLocationAccuracyBestForNavigation
if #available(iOS 9.0, *) {
self.locationManager!.allowsBackgroundLocationUpdates = true
}
if ridePreferences?.locationUpdateAccuracy == 1{
self.locationManager!.distanceFilter = Double(AppConfiguration.MIN_DISTANCE_CHANGE_FOR_UPDATES_MEDIUM)
}else if ridePreferences?.locationUpdateAccuracy == 2{
self.locationManager!.distanceFilter = Double(AppConfiguration.MIN_DISTANCE_CHANGE_FOR_UPDATES_HIGH)
}
self.locationManager!.desiredAccuracy = kCLLocationAccuracyBestForNavigation
self.locationManager!.pausesLocationUpdatesAutomatically = true
self.locationManager!.activityType = CLActivityType.automotiveNavigation
self.locationManager!.delegate = self
self.locationManager!.startUpdatingLocation()
let appDelegate : AppDelegate = UIApplication.shared.delegate as! AppDelegate
appDelegate.startLocationManager()
locationUpdateToServerTask = UserLocationUpdateToServerTask()
if locationManager?.location != nil{
locationUpdateToServerTask?.setLatestLocation(newLocation: (locationManager?.location)!)
processLocationUpdate(location: (locationManager?.location)!)
}
The crash is happening in this line as per the crashlytics report :-
self.locationManager!.pausesLocationUpdatesAutomatically = true
Can some one help me out ? Thanks in advance
I am unable to replicate this issue, how to replicate the following fabric crash ?
Is there a way to open this crash in xcode (Importing crash into xcode)
Crashed: com.apple.main-thread
0 ABCC 0x10092d0c4 specialized ABCViewController.signInBtnPressed(UIButton) -> ()(ABCViewController.swift:178)
1 ABCC 0x10092a520 #objc ABCViewController.unwind(UIStoryboardSegue) -> () + 3152641510
2 UIKit 0x18aced64c -[UIApplication sendAction:to:from:forEvent:] + 86
3 UIKit 0x18ae0e870 -[UIControl sendAction:to:forEvent:] + 52
4 UIKit 0x18acf3700 -[UIControl _sendActionsForEvents:withEvent:] + 120
5 UIKit 0x18ae291a8 -[UIControl touchesEnded:withEvent:] + 492
6 UIKit 0x18b2ceee8 _UIGestureEnvironmentSortAndSendDelayedTouches + 4340
7 UIKit 0x18b2cbc60 _UIGestureEnvironmentUpdate + 1236
8 UIKit 0x18ad664d8 -[UIGestureEnvironment _deliverEvent:toGestureRecognizers:usingBlock:] + 404
9 UIKit 0x18ad66010 -[UIGestureEnvironment _updateGesturesForEvent:window:] + 276
10 UIKit 0x18ad65874 -[UIWindow sendEvent:] + 3132
11 UIKit 0x18ad641d0 -[UIApplication sendEvent:] + 340
12 UIKit 0x18b545d1c __dispatchPreprocessedEventFromEventQueue + 2340
13 UIKit 0x18b5482c8 __handleEventQueueInternal + 4744
14 CoreFoundation 0x180f27404 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
15 CoreFoundation 0x180f26c2c __CFRunLoopDoSources0 + 276
16 CoreFoundation 0x180f2479c __CFRunLoopRun + 1204
17 CoreFoundation 0x180e44da8 CFRunLoopRunSpecific + 552
18 GraphicsServices 0x182e2a020 GSEventRunModal + 100
19 UIKit 0x18ae64758 UIApplicationMain + 236
20 ABCC 0x1007b28c4 main (main.m:20)
21 libdyld.dylib 0x1808d5fc0 start + 4
Here is the code for the action that is crashing.
#IBAction func signInBtnPressed(_ sender: UIButton) {
sender.isUserInteractionEnabled = false
guard let employees = UserService.shared.employees, let name = employees.names?[sender.tag] else {
sender.isUserInteractionEnabled = true // crashing here
return
}
// perform task
sender.isUserInteractionEnabled = true
}
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)
This is the crash log I got from Crashlytics:
Thread : Crashed: com.apple.main-thread
0 Trenìt! 0x1000b93e4 SearchHistoryProvider.getMostRecentStations(Int) -> [String] (SearchHistoryProvider.swift)
1 Trenìt! 0x10007985c specialized MasterViewController.onTouchedTextField(UITextField) -> () (MasterViewController.swift:265)
2 Trenìt! 0x100075414 #objc MasterViewController.onTouchedTextField(UITextField) -> () (MasterViewController.swift)
3 UIKit 0x186fa0ad0 -[UIApplication sendAction:to:from:forEvent:] + 100
4 UIKit 0x186fa0a4c -[UIControl sendAction:to:forEvent:] + 80
5 UIKit 0x186f88740 -[UIControl _sendActionsForEvents:withEvent:] + 436
6 UIKit 0x186fa9248 -[UIControl touchesBegan:withEvent:] + 400
7 UIKit 0x186f9fdc0 -[UIWindow _sendTouchesForEvent:] + 376
8 UIKit 0x186f98b08 -[UIWindow sendEvent:] + 784
9 UIKit 0x186f68f4c -[UIApplication sendEvent:] + 248
10 UIKit 0x186f67528 _UIApplicationHandleEventQueue + 6568
11 CoreFoundation 0x181dd5124 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
12 CoreFoundation 0x181dd4bb8 __CFRunLoopDoSources0 + 540
13 CoreFoundation 0x181dd28b8 __CFRunLoopRun + 724
14 CoreFoundation 0x181cfcd10 CFRunLoopRunSpecific + 384
15 GraphicsServices 0x1835e4088 GSEventRunModal + 180
16 UIKit 0x186fd1f70 UIApplicationMain + 204
17 Trenìt! 0x10009b2fc main (AppDelegate.swift:14)```
(edited)
and this is my code:
MasterViewController.swift:
263 func showRecentStations(textField: UITextField) {
264 textField.text = ""
265 suggestionStations = masterContainerManager!.homeController?.searchHistoryProvider?.getMostRecentStations(10)
266 updateStationsTable(textField)
267 }
SearchHistoryProvider.swift
func getMostRecentStations (maxSize : Int) -> [String] {
let stationsByOldestArray = getRecentStationsByOldest()
let stations = NSMutableOrderedSet()
for i in (0...(stationsByOldestArray.count-1)).reverse() {
stations.addObject(stationsByOldestArray[i].depStation)
if stations.count==maxSize {
return stations.array as! [String]
}
stations.addObject(stationsByOldestArray[i].arrStation)
if stations.count==maxSize {
return stations.array as! [String]
}
}
return stations.array as! [String]
}
Can anyone understand what's the crash about?
I found the bug:
in case stationsByOldestArray.count was 0
the for loop would have been
for i in (0...-1).reverse()
I fixed it by rewriting the loop as
for i in (0..<stationsByOldestArray.count).reverse()
However I think the Swift crash reports are often hopelessly unhelpful!