如何理解无意义的Swift堆栈跟踪?

时间:2015-07-11 23:54:02

标签: ios swift

从Crashlytics获取以下堆栈跟踪。

崩溃的代码是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 */
    }

}

代码指向return语句。我可以想到这次崩溃的唯一原因是string为零,这是不可能的,因为如果它是零,则在调用addAttribute时它会在上面的行上崩溃。获取大量这些崩溃和堆栈跟踪绝对没有说明导致它的原因

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

1 个答案:

答案 0 :(得分:1)

属性字符串的范围必须为UTF-16单位。