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 have a situation where try NSAttributedString(data: data, options: [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType], documentAttributes: nil) crashes the app.
In the console it says:
Assertion failure in void _prepareForCAFlush(UIApplication *__strong)()
The function is called in an extension String.
When I 'po' values in the console:
(lldb) po self
<p>Obfuscated string\n</p>
(lldb) po data`
450 bytes
count : 450
pointer : 0x00007fd283d75630
pointerValue : 140542131787312
(lldb) po NSAttributedString(data: data, options: [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType], documentAttributes: nil)
Obfuscated string
{
NSColor = "kCGColorSpaceModelRGB 0 0 0 1 ";
NSFont = "<UICTFont: 0x7fd283c47330> font-family: \"Helvetica\"; font-weight: normal; font-style: normal; font-size: 15.00pt";
NSKern = 0;
NSParagraphStyle = "Alignment 4, LineSpacing 0, ParagraphSpacing 15, ParagraphSpacingBefore 0, HeadIndent 0, TailIndent 0, FirstLineHeadIndent 0, LineHeight 19/0, LineHeightMultiple 0, LineBreakMode 0, Tabs (\n), DefaultTabInterval 36, Blocks (\n), Lists (\n), BaseWritingDirection 0, HyphenationFactor 0, TighteningForTruncation NO, HeaderLevel 0";
NSStrokeColor = "kCGColorSpaceModelRGB 0 0 0 1 ";
NSStrokeWidth = 0;
}
The string exists in a label, that is displayed in a UITableViewCell.
The function crashes in a specific case, when the "keyboard frame changes".
The Table Cells are being drawn again by iOS and this causes to redraw their content.
The crash happens on the main thread, so the function is being called on the main thread.
What could be the cause of this crash and how could I possibly resolve it?
EDIT: Table view cell code
UITableViewDataSource to generate the cell:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cellID = cellIdentifier(for: message)
let cell = tableView.dequeueReusableCell(withIdentifier: cellID) as! MessageTableViewCell
cell.message = message
cell.setOutletValues()
cell.selectionStyle = .none
cell.delegate = self
return cell
}
Implementaion of the Cell:
class MessageTableViewCell: UITableViewCell {
var message: Message!
// Message Body View
#IBOutlet weak var messageBodyView: ZeroPaddingTextView!
func setOutletValues() {
setMessageBodyOutletValues()
}
internal func setMessageBodyOutletValues() {
if let body = message.body {
messageBodyView.attributedText = body.htmlToPlainAttributedString()
}
}
}
And the function to create a plain attributed string, it does a few additions tothe HTML for styling (this is due to the content that comes in through the API, it needs some additions).
func htmlToPlainAttributedString() -> NSAttributedString {
let contentString = replacingOccurrences(of: "\n", with: "<br>")
let styleSheet = "body {font-family: sans-serif; font-size: 15px; color: #000000;}\n a {text-decoration: none;}\n"
let body = "<body>\(contentString)</body>"
let html = "<html><head><style type=\"text/css\">\(styleSheet)</style></head>\(body)</html>"
if let data = html.data(using: String.Encoding.unicode, allowLossyConversion: true) {
do {
return try NSAttributedString(data: data, options: [
NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType], documentAttributes: nil)
} catch {
return NSAttributedString()
}
}
return NSAttributedString()
}
Console crash output:
2017-09-05 22:37:14.692 trustedfamily-ios[70389:10080542] *** Assertion failure in void _prepareForCAFlush(UIApplication *__strong)(), /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3600.7.47/UIApplication.m:2395
2017-09-05 22:38:14.532 trustedfamily-ios[70389:10080542] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'unexpected start state'
*** First throw call stack:
(
0 CoreFoundation 0x000000010452ab0b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x00000001035e8141 objc_exception_throw + 48
2 CoreFoundation 0x000000010452ecf2 +[NSException raise:format:arguments:] + 98
3 Foundation 0x00000001031b769b -[NSAssertionHandler handleFailureInFunction:file:lineNumber:description:] + 165
4 UIKit 0x0000000105a31575 _prepareForCAFlush + 499
5 UIKit 0x0000000105a6346b _beforeCACommitHandler + 15
6 CoreFoundation 0x00000001044d0717 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
7 CoreFoundation 0x00000001044d0687 __CFRunLoopDoObservers + 391
8 CoreFoundation 0x00000001044b5038 CFRunLoopRunSpecific + 440
9 UIFoundation 0x000000010a103edc -[NSHTMLReader _loadUsingWebKit] + 1954
10 UIFoundation 0x000000010a10522a -[NSHTMLReader attributedString] + 22
11 UIFoundation 0x000000010a09ded6 _NSReadAttributedStringFromURLOrData + 8926
12 UIFoundation 0x000000010a09bb64 -[NSAttributedString(NSAttributedStringUIFoundationAdditions) initWithData:options:documentAttributes:error:] + 117
13 trustedfamily-ios 0x0000000101e9e6ad _TTOFE5UIKitCSo18NSAttributedStringcfzT4dataV10Foundation4Data7optionsGVs10DictionarySSP__18documentAttributesGSqGVs33AutoreleasingUnsafeMutablePointerGSqCSo12NSDictionary____S0_ + 173
14 trustedfamily-ios 0x0000000101e9d9d9 _TFE5UIKitCSo18NSAttributedStringCfzT4dataV10Foundation4Data7optionsGVs10DictionarySSP__18documentAttributesGSqGVs33AutoreleasingUnsafeMutablePointerGSqCSo12NSDictionary____S0_ + 89
15 trustedfamily-ios 0x0000000101e9d803 _TFE17trustedfamily_iosSS27htmlToPlainAttributedStringfT_CSo18NSAttributedString + 1459
16 trustedfamily-ios 0x00000001020152f9 _TFC17trustedfamily_ios20MessageTableViewCell26setMessageBodyOutletValuesfT_T_ + 601
17 trustedfamily-ios 0x0000000102013467 _TFC17trustedfamily_ios20MessageTableViewCell15setOutletValuesfT_T_ + 103
18 trustedfamily-ios 0x0000000101f9a22f _TFC17trustedfamily_ios32ConversationDetailViewController9tableViewfTCSo11UITableView12cellForRowAtV10Foundation9IndexPath_CSo15UITableViewCell + 1199
19 trustedfamily-ios 0x0000000101f9a4d7 _TToFC17trustedfamily_ios32ConversationDetailViewController9tableViewfTCSo11UITableView12cellForRowAtV10Foundation9IndexPath_CSo15UITableViewCell + 87
20 UIKit 0x0000000105ba4ab2 -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 750
21 UIKit 0x0000000105ba4cf8 -[UITableView _createPreparedCellForGlobalRow:willDisplay:] + 74
22 UIKit 0x0000000105b79639 -[UITableView _updateVisibleCellsNow:isRecursive:] + 2845
23 UIKit 0x0000000105b774a4 -[UITableView _setNeedsVisibleCellsUpdate:withFrames:] + 201
24 UIKit 0x0000000105b9626a -[UITableView _rectChangedWithNewSize:oldSize:] + 1267
25 UIKit 0x0000000105b96a5c -[UITableView setBounds:] + 322
26 UIKit 0x0000000105adee73 -[UIView(Geometry) _applyISEngineLayoutValuesToBoundsOnly:] + 598
27 UIKit 0x0000000105adf15e -[UIView(Geometry) _resizeWithOldSuperviewSize:] + 125
28 UIKit 0x000000010648f0e9 -[UIScrollView(_UIOldConstraintBasedLayoutSupport) _resizeWithOldSuperviewSize:] + 46
29 CoreFoundation 0x00000001044bb652 __53-[__NSArrayM enumerateObjectsWithOptions:usingBlock:]_block_invoke + 114
30 CoreFoundation 0x00000001044bb56f -[__NSArrayM enumerateObjectsWithOptions:usingBlock:] + 335
31 UIKit 0x0000000105addbcc -[UIView(Geometry) resizeSubviewsWithOldSize:] + 183
32 UIKit 0x00000001063fa16d -[UIView(AdditionalLayoutSupport) _is_layout] + 168
33 UIKit 0x0000000105aea0a6 -[UIView(Hierarchy) _updateConstraintsAsNecessaryAndApplyLayoutFromEngine] + 994
34 UIKit 0x0000000105afb55b -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1268
35 QuartzCore 0x00000001057a4904 -[CALayer layoutSublayers] + 146
36 QuartzCore 0x0000000105798526 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 370
37 UIKit 0x0000000105ae9334 -[UIView(Hierarchy) layoutBelowIfNeeded] + 1108
38 trustedfamily-ios 0x0000000101fe3f4c _TFC17trustedfamily_ios32ConversationDetailViewController28changeBottomLayoutConstraintfT2toV12CoreGraphics7CGFloat_T_ + 284
39 trustedfamily-ios 0x0000000101fe3fac _TToFC17trustedfamily_ios32ConversationDetailViewController28changeBottomLayoutConstraintfT2toV12CoreGraphics7CGFloat_T_ + 44
40 trustedfamily-ios 0x0000000101fe3bf7 _TFFC17trustedfamily_ios32ConversationDetailViewController28changeBottomLayoutConstraintFT2toV12CoreGraphics7CGFloat8animatedSb8durationSd7optionsVSC22UIViewAnimationOptions_T_U_FT_T_ + 39
41 trustedfamily-ios 0x0000000101e572d7 _TTRXFo___XFdCb___ + 39
42 UIKit 0x0000000105af13da +[UIView(UIViewAnimationWithBlocks) _setupAnimationWithDuration:delay:view:options:factory:animations:start:animationStateGenerator:completion:] + 572
43 UIKit 0x0000000105af18dd +[UIView(UIViewAnimationWithBlocks) animateWithDuration:delay:options:animations:completion:] + 99
44 trustedfamily-ios 0x0000000101fe3b7f _TFC17trustedfamily_ios32ConversationDetailViewController28changeBottomLayoutConstraintfT2toV12CoreGraphics7CGFloat8animatedSb8durationSd7optionsVSC22UIViewAnimationOptions_T_ + 943
45 trustedfamily-ios 0x0000000101fe3e1f _TToFC17trustedfamily_ios32ConversationDetailViewController28changeBottomLayoutConstraintfT2toV12CoreGraphics7CGFloat8animatedSb8durationSd7optionsVSC22UIViewAnimationOptions_T_ + 79
46 trustedfamily-ios 0x0000000101fe30e6 _TFC17trustedfamily_ios32ConversationDetailViewController23keyboardWillChangeFramefV10Foundation12NotificationT_ + 2278
47 trustedfamily-ios 0x0000000101fe3237 _TToFC17trustedfamily_ios32ConversationDetailViewController23keyboardWillChangeFramefV10Foundation12NotificationT_ + 71
48 CoreFoundation 0x00000001044c9c2c __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 12
49 CoreFoundation 0x00000001044c9b29 _CFXRegistrationPost + 425
50 CoreFoundation 0x00000001044c9892 ___CFXNotificationPost_block_invoke + 50
51 CoreFoundation 0x000000010448d102 -[_CFXNotificationRegistrar find:object:observer:enumerator:] + 1826
52 CoreFoundation 0x000000010448c261 _CFXNotificationPost + 673
53 Foundation 0x00000001030b6ca4 -[NSNotificationCenter postNotificationName:object:userInfo:] + 66
54 UIKit 0x000000010649ce05 -[UIInputWindowController postStartNotifications:withInfo:] + 225
55 UIKit 0x000000010649f0af __77-[UIInputWindowController moveFromPlacement:toPlacement:starting:completion:]_block_invoke.871 + 381
56 UIKit 0x0000000105af13da +[UIView(UIViewAnimationWithBlocks) _setupAnimationWithDuration:delay:view:options:factory:animations:start:animationStateGenerator:completion:] + 572
57 UIKit 0x0000000105af1853 +[UIView(UIViewAnimationWithBlocks) _animateWithDuration:delay:options:animations:start:completion:] + 116
58 UIKit 0x000000010649eacb -[UIInputWindowController moveFromPlacement:toPlacement:starting:completion:] + 1503
59 UIKit 0x00000001064a6d5e __43-[UIInputWindowController setInputViewSet:]_block_invoke.1318 + 97
60 UIKit 0x000000010649a59a -[UIInputWindowController performOperations:withTemplateNotificationInfo:] + 46
61 UIKit 0x00000001064a68ea -[UIInputWindowController setInputViewSet:] + 1753
62 UIKit 0x000000010649e14c -[UIInputWindowController performOperations:withAnimationStyle:] + 50
63 UIKit 0x0000000106114a8a -[UIPeripheralHost(UIKitInternal) setInputViews:animationStyle:] + 1505
64 UIKit 0x0000000106115c4b -[UIPeripheralHost(UIKitInternal) _preserveInputViewsWithId:animated:reset:] + 499
65 UIKit 0x0000000105bec35d -[UIViewController _presentViewController:modalSourceViewController:presentationController:animationController:interactionController:completion:] + 1145
66 UIKit 0x0000000105bedfae -[UIViewController _presentViewController:withAnimationController:completion:] + 4660
67 CoreFoundation 0x00000001044b2c6c __invoking___ + 140
68 CoreFoundation 0x00000001044b2b40 -[NSInvocation invoke] + 320
69 UIKit 0x0000000105bd1633 -[_UIDelayedPresentationContext finishDelayedPresentation:] + 230
70 UIKit 0x0000000105be9416 -[UIViewController _endDelayingPresentation] + 93
71 CoreFoundation 0x00000001044b2c6c __invoking___ + 140
72 CoreFoundation 0x00000001044b2b40 -[NSInvocation invoke] + 320
73 FrontBoardServices 0x000000010a1f25f6 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 24
74 FrontBoardServices 0x000000010a1f246d -[FBSSerialQueue _performNext] + 186
75 FrontBoardServices 0x000000010a1cb360 -[FBSWorkspace synchronizeSystemAnimationFencesWithCleanUpBlock:] + 1549
76 UIKit 0x0000000105a311d4 -[UIApplication _synchronizeSystemAnimationFencesWithSpinCleanUpBlock:] + 543
77 UIKit 0x0000000105ab22cd __realPreCommitHandler_block_invoke + 395
78 QuartzCore 0x000000010575532c _ZNK2CA11Transaction5Fence13run_callbacksEv + 40
79 QuartzCore 0x0000000105727f7c _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 528
80 QuartzCore 0x0000000105754130 _ZN2CA11Transaction6commitEv + 468
81 QuartzCore 0x0000000105754b37 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 115
82 CoreFoundation 0x00000001044d0717 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
83 CoreFoundation 0x00000001044d0687 __CFRunLoopDoObservers + 391
84 CoreFoundation 0x00000001044b5720 __CFRunLoopRun + 1200
85 CoreFoundation 0x00000001044b5016 CFRunLoopRunSpecific + 406
86 GraphicsServices 0x000000010a9eda24 GSEventRunModal + 62
87 UIKit 0x0000000105a38134 UIApplicationMain + 159
88 trustedfamily-ios 0x0000000101ff6837 main + 55
89 libdyld.dylib 0x000000010894465d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Try to make your html convert in NSAttributedString inside
DispatchQueue.main.async {
}
I'm seeing this crash in a very similar situation in the field but can't reproduce it myself.
Let's try this and see if it helps:
guard UIApplication.shared.applicationState == .active else { return NSAttributedString() }
I'm getting this crash on crashlytics (fabric), but unable to reproduce it or understand its origin based on the traceback.
Crashed: com.apple.main-thread
0 MyApp 0x1001080a0 MyViewController.viewWillAppear(Bool) -> () (MyViewController.swift:135)
1 MyApp 0x1001080d0 #objc MyViewController.viewWillAppear(Bool) -> () (MyViewController.swift)
2 UIKit 0x18868bbf4 -[UIViewController _setViewAppearState:isAnimating:] + 632
3 UIKit 0x18868b964 -[UIViewController __viewWillAppear:] + 156
4 UIKit 0x1888101d4 -[UINavigationController _startCustomTransition:] + 1144
5 UIKit 0x18872ab78 -[UINavigationController _startDeferredTransitionIfNeeded:] + 676
6 UIKit 0x18872a7e0 -[UINavigationController __viewWillLayoutSubviews] + 64
7 UIKit 0x18872a744 -[UILayoutContainerView layoutSubviews] + 188
8 UIKit 0x18867107c -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1200
9 QuartzCore 0x185861274 -[CALayer layoutSublayers] + 148
10 QuartzCore 0x185855de8 CA::Layer::layout_if_needed(CA::Transaction*) + 292
11 QuartzCore 0x185855ca8 CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 32
12 QuartzCore 0x1857d134c CA::Context::commit_transaction(CA::Transaction*) + 252
13 QuartzCore 0x1857f83ac CA::Transaction::commit() + 504
14 UIKit 0x1888f2524 _UIApplicationFlushRunLoopCATransactionIfTooLate + 172
15 UIKit 0x188e689f8 __handleEventQueue + 4916
16 UIKit 0x188e68b9c __handleHIDEventFetcherDrain + 148
17 CoreFoundation 0x1824f142c __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
18 CoreFoundation 0x1824f0d9c __CFRunLoopDoSources0 + 540
19 CoreFoundation 0x1824ee9a8 __CFRunLoopRun + 744
20 CoreFoundation 0x18241eda4 CFRunLoopRunSpecific + 424
21 GraphicsServices 0x183e88074 GSEventRunModal + 100
22 UIKit 0x1886d9058 UIApplicationMain + 208
23 MyApp 0x1009052fc main (AppDelegate.swift:16)
24 libdyld.dylib 0x18142d59c start + 4
The code in MyViewController:
#IBOutlet weak var someConstraint: NSLayoutConstraint!
#IBOutlet weak var button: UIButton!
let minHeight: CGFloat = 2.0
let cValue: CGFloat = 32.0
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
let aValue = button.frame.origin.y - UIApplication.shared.statusBarFrame.height
let bValue = button.bounds.height + minHeight
someConstraint.constant = max(aValue - bValue, cValue) // --> Crash here, line 135
}
Update: SomeConstraint is not nil.
I want to scroll my tableview to bottom when keyboard appears. But i am getting lot of crash reports from my users.
My code:
func keyboardWillShow(_ notification: Foundation.Notification) {
var info = notification.userInfo!
let keyboardFrame: CGRect = (info[UIKeyboardFrameEndUserInfoKey] as! NSValue).cgRectValue
self.view.layoutIfNeeded()
UIView.animate(withDuration: 0.2, animations: {
self.bottomCons.constant = keyboardFrame.size.height
self.view.layoutIfNeeded()
})
let numberOfRows = tableView.numberOfRows(inSection: 0)
if numberOfRows != 0 {
do {
try tableView.scrollToRow(at: IndexPath(row: numberOfRows-1, section: 0), at: .bottom, animated: false)
}catch {
print("error")
}
}
}
Crash log:
Fatal Exception: NSRangeException
0 CoreFoundation 0x18f3bafe0 __exceptionPreprocess
1 libobjc.A.dylib 0x18de1c538 objc_exception_throw
2 CoreFoundation 0x18f299200 -[__NSArrayM removeObjectAtIndex:]
3 UIKit 0x195826f90 -[UITableView _existingCellForRowAtIndexPath:]
4 UIKit 0x195836a50 -[UITableView _heightForRowAtIndexPath:]
5 UIKit 0x1956291c0 -[UISectionRowData heightForRow:inSection:canGuess:]
6 UIKit 0x195628ebc -[UITableViewRowData rectForRow:inSection:heightCanBeGuessed:]
7 UIKit 0x19562c21c -[UITableView rectForRowAtIndexPath:]
8 UIKit 0x195704180 -[UITableView _contentOffsetForScrollingToRowAtIndexPath:atScrollPosition:]
9 UIKit 0x195703c84 -[UITableView scrollToRowAtIndexPath:atScrollPosition:animated:]
10 Ribony 0x1000a3044 ChatViewController.keyboardWillShow(Notification) -> () (ChatViewController.swift)
11 Ribony 0x1000a07d4 #objc ChatViewController.showConnectedLayout(Notification) -> ()
12 CoreFoundation 0x18f3555f4 __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__
13 CoreFoundation 0x18f354d08 _CFXRegistrationPost
14 CoreFoundation 0x18f354a84 ___CFXNotificationPost_block_invoke
15 CoreFoundation 0x18f3c37a8 -[_CFXNotificationRegistrar find:object:observer:enumerator:]
16 CoreFoundation 0x18f29895c _CFXNotificationPost
17 Foundation 0x18fdaa930 -[NSNotificationCenter postNotificationName:object:userInfo:]
18 UIKit 0x195ed0190 -[UIInputWindowController postStartNotifications:withInfo:]
19 UIKit 0x195ed0edc __48-[UIInputWindowController viewDidLayoutSubviews]_block_invoke
20 UIKit 0x195ecdc04 -[UIInputWindowController performWithSafeTransitionFrames:]
21 UIKit 0x195ed098c -[UIInputWindowController viewDidLayoutSubviews]
22 UIKit 0x1954e90f4 -[UIView(CALayerDelegate) layoutSublayersOfLayer:]
23 QuartzCore 0x1926d9274 -[CALayer layoutSublayers]
24 QuartzCore 0x1926cdde8 CA::Layer::layout_if_needed(CA::Transaction*)
25 UIKit 0x1954fd814 -[UIView(Hierarchy) layoutBelowIfNeeded]
26 UIKit 0x195ecc4cc -[UIInputSetHostView layoutIfNeeded]
27 UIKit 0x195c79310 -[_UIRemoteKeyboards controllerDidLayoutSubviews:]
28 UIKit 0x195d49364 -[UICompatibilityInputViewController viewDidLayoutSubviews]
29 UIKit 0x1954e90f4 -[UIView(CALayerDelegate) layoutSublayersOfLayer:]
30 QuartzCore 0x1926d9274 -[CALayer layoutSublayers]
31 QuartzCore 0x1926cdde8 CA::Layer::layout_if_needed(CA::Transaction*)
32 UIKit 0x1954fd814 -[UIView(Hierarchy) layoutBelowIfNeeded]
33 UIKit 0x195ecc4cc -[UIInputSetHostView layoutIfNeeded]
34 UIKit 0x195ed4da0 -[UIInputWindowController _updateBackdropViews]
35 UIKit 0x195d4823c -[UICompatibilityInputViewController setInputMode:]
36 CoreFoundation 0x18f3555f4 __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__
37 CoreFoundation 0x18f354d08 _CFXRegistrationPost
38 CoreFoundation 0x18f354a84 ___CFXNotificationPost_block_invoke
39 CoreFoundation 0x18f3c37a8 -[_CFXNotificationRegistrar find:object:observer:enumerator:]
40 CoreFoundation 0x18f29895c _CFXNotificationPost
41 Foundation 0x18fdaa930 -[NSNotificationCenter postNotificationName:object:userInfo:]
42 UIKit 0x195908be4 -[UIKeyboardImpl setKeyboardInputMode:userInitiated:updateIndicator:executionContext:]
43 UIKit 0x19590a388 -[UIKeyboardImpl setInputModeToNextInPreferredListWithExecutionContext:]
44 UIKit 0x1956aed88 -[UIKeyboardLayoutStar completeSendStringActionForTouchUp:withActions:timestamp:interval:didLongPress:prevActions:executionContext:]
45 UIKit 0x1956a1f18 -[UIKeyboardLayoutStar completeRetestForTouchUp:timestamp:interval:executionContext:]
46 UIKit 0x19592bbb8 __45-[UIKeyboardLayout touchUpTaskForTouchState:]_block_invoke
47 UIKit 0x195515e0c -[UIKeyboardTaskQueue continueExecutionOnMainThread]
48 UIKit 0x19592b868 -[UIKeyboardLayout _touchEndedProcessingForTouches:]
49 UIKit 0x195520390 -[UIWindow _sendTouchesForEvent:]
50 UIKit 0x19551b728 -[UIWindow sendEvent:]
51 UIKit 0x1954ec33c -[UIApplication sendEvent:]
52 UIKit 0x195ce6014 __dispatchPreprocessedEventFromEventQueue
53 UIKit 0x195ce0770 __handleEventQueue
54 UIKit 0x195ce0b9c __handleHIDEventFetcherDrain
55 CoreFoundation 0x18f36942c __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__
56 CoreFoundation 0x18f368d9c __CFRunLoopDoSources0
57 CoreFoundation 0x18f3669a8 __CFRunLoopRun
58 CoreFoundation 0x18f296da4 CFRunLoopRunSpecific
59 GraphicsServices 0x190d00074 GSEventRunModal
60 UIKit 0x195551058 UIApplicationMain
61 Ribony 0x10003f11c main (AppDelegate.swift:15)
62 libdyld.dylib 0x18e2a559c start
How can i resolve this issue?
I am convinced problem lays here
UIView.animate(withDuration: 0.2, animations: {
self.bottomCons.constant = keyboardFrame.size.height
self.view.layoutIfNeeded()
})
...
try tableView.scrollToRow(at: IndexPath(row: numberOfRows-1, section: 0), at: .bottom, animated: false)
You are reloading layout and trying to scroll in the very same moment, you should scroll afterwards or before. Might be I am not right, but this is usually the problem.
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!