2015-07-11 41 views
1

從Crashlytics獲取以下堆棧跟蹤。被撞毀如何理解無意義的Swift棧跟蹤?

代碼是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

屬性字符串的範圍必須是UTF-16單位。

+0

你能詳細說明一下嗎?代碼並不總是崩潰。我不能事件重現崩潰。日誌來自崩潰報告工具。並且崩潰也不在該行上,它位於 – aryaxt

+0

以下的行上。已賦值字符串基於Objective-C字符串。 Objective-C字符串使用UTF-16。屬性字符串的範圍必須以UTF-16單位計算字符數。你的代碼計算String使用的任何單位。根據你擁有的字符和計數的不同,崩潰將會發生。 – gnasher729

+0

謝謝,會做出改變,看看我是否再次遇到這個崩潰 – aryaxt