aryaxt
aryaxt

Reputation: 77646

How to understand the meaningless Swift stack traces?

Getting the following stack trace from Crashlytics.

Code that is crashing is return string

extension UserVisit: DashboardItem {

    public var dashboardItemAttributedTitle: NSAttributedString {
        let string = NSMutableAttributedString(string: "\(withUser.publicName) (\(withUser.publicAddress.fullDescription))", attributes: [NSFontAttributeName: UIFont.regularLight()])
        string.addAttribute(NSFontAttributeName, value: UIFont.regularBold(), range: NSMakeRange(0 , count(withUser.publicName)))
        return string  /*  Crash points to this line of code */
    }

}

The code points to the return statement. The only reason I can think of for this crash is string being nil, which is not possible because if it was nil it would have crashed on the line above when addAttribute was called. Getting lots of these crashes and the stacktrace says absolutely nothing about what's causing it

Thread : Crashed: com.apple.main-thread
0  Company                   0x00000001001c05c0 function signature specialization <Arg[0] = Owned To Guaranteed> of Company.UserVisit.dashboardItemAttributedTitle.getter : ObjectiveC.NSAttributedString (DashboardItemExtensions.swift:122)
1  Company                   0x00000001001be674 @objc Company.UserVisit.dashboardItemAttributedTitle.getter : ObjectiveC.NSAttributedString (DashboardItemExtensions.swift)
2  Company                   0x00000001001d3618 function signature specialization <Arg[0] = Owned To Guaranteed, Arg[1] = Owned To Guaranteed> of Company.DashboardItemCell.configure (Company.DashboardItemCell)(Company.DashboardItem) -> () (DashboardItemCell.swift:93)
3  Company                   0x00000001001d100c Company.DashboardItemCell.configure (Company.DashboardItemCell)(Company.DashboardItem) -> () (DashboardItemCell.swift)
4  Company                   0x0000000100163cb4 function signature specialization <Arg[0] = Owned To Guaranteed, Arg[1] = Owned To Guaranteed, Arg[2] = Owned To Guaranteed> of Company.DashboardViewController.collectionView (Company.DashboardViewController)(ObjectiveC.UICollectionView, cellForItemAtIndexPath : ObjectiveC.NSIndexPath) -> ObjectiveC.UICollectionViewCell (DashboardViewController.swift:567)
5  Company                   0x000000010015f3b8 @objc Company.DashboardViewController.collectionView (Company.DashboardViewController)(ObjectiveC.UICollectionView, cellForItemAtIndexPath : ObjectiveC.NSIndexPath) -> ObjectiveC.UICollectionViewCell (DashboardViewController.swift)
6  UIKit                          0x0000000187650710 -[UICollectionView _createPreparedCellForItemAtIndexPath:withLayoutAttributes:applyAttributes:] + 284
7  UIKit                          0x0000000187c7a850 __51-[UICollectionView _viewAnimationsForCurrentUpdate]_block_invoke1381 + 480
8  UIKit                          0x00000001877c5164 -[UICollectionView _viewAnimationsForCurrentUpdate] + 2892
9  UIKit                          0x0000000187c7b694 -[UICollectionView _updateWithItems:tentativelyForReordering:] + 1948
10 UIKit                          0x0000000187c79c30 -[UICollectionView _endItemAnimationsWithInvalidationContext:tentativelyForReordering:] + 10120
11 UIKit                          0x0000000187c7c988 -[UICollectionView _performBatchUpdates:completion:invalidationContext:tentativelyForReordering:] + 352
12 Company                   0x000000010016c214 Company.DashboardViewController.((fetchAndPopulateDashboard in _59C7F3AF672DD71404DED200B8F15814) (Company.DashboardViewController) -> () -> ()).(closure #1) (DashboardViewController.swift:370)
13 Company                   0x00000001000e1728 Company.BaseNetworkManager.(fetchObject (Company.BaseNetworkManager) -> <A>(A.Type, path : Swift.String, method : Company.Method, parameters : Swift.Optional<Swift.Dictionary<ObjectiveC.NSObject, Swift.AnyObject>>, errorHandler : Company.NetworkErrorHandler, completion : (Company.SingleNetworkResponse<A>) -> ()) -> Company.RequestMirror).(closure #1).(closure #1).(closure #1) (BaseNetworkManager.swift:219)
14 libdispatch.dylib              0x0000000194e6d994 _dispatch_call_block_and_release + 24
15 libdispatch.dylib              0x0000000194e6d954 _dispatch_client_callout + 16
16 libdispatch.dylib              0x0000000194e7220c _dispatch_main_queue_callback_4CF + 1608
17 CoreFoundation                 0x0000000182b2b7f8 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 12
18 CoreFoundation                 0x0000000182b298a0 __CFRunLoopRun + 1492
19 CoreFoundation                 0x0000000182a552d4 CFRunLoopRunSpecific + 396
20 GraphicsServices               0x000000018c4b36fc GSEventRunModal + 168
21 UIKit                          0x0000000187652f40 UIApplicationMain + 1488
22 Company                   0x000000010003ac1c main (main.m:13)
23 libdyld.dylib                  0x0000000194e9aa08 start + 4

Upvotes: 1

Views: 567

Answers (1)

gnasher729
gnasher729

Reputation: 52622

The range for an attributed string must be in UTF-16 units.

Upvotes: 1

Related Questions