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

Ios 如何理解无意义的Swift堆栈跟踪?,ios,swift,Ios,Swift,从Crashlytics获取以下堆栈跟踪 正在崩溃的代码是返回字符串 extension UserVisit: DashboardItem { public var dashboardItemAttributedTitle: NSAttributedString { let string = NSMutableAttributedString(string: "\(withUser.publicName) (\(withUser.publicAddress.fullDe

从Crashlytics获取以下堆栈跟踪

正在崩溃的代码是返回字符串

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
为nil,这是不可能的,因为如果为nil,则在调用
addAttribute
时,它会在上面一行崩溃。有很多这样的崩溃,stacktrace完全没有说明是什么原因造成的

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
线程:崩溃:com.apple.main-Thread
0 Company 0x00000001001c05c0 Company.UserVisit.dashboardItemAttributedTitle.getter的函数签名专用化:Objective.NSAttribute字符串(DashboardItemExtensions.swift:122)
1公司0x00000001001be674@objc Company.UserVisit.dashboardItemAttributedTitle.getter:ObjectiveC.nsAttribute字符串(DashboardItemExtensions.swift)
2公司0x00000001001d3618 Company.DashboardItemCell.configure(Company.DashboardItemCell)(Company.DashboardItemCell)->()(DashboardItemCell.swift:93)的功能签名专门化
3公司0x00000001001d100c公司.DashboardItemCell.configure(公司.DashboardItemCell)(公司.DashboardItem)->()(DashboardItemCell.swift)
4 Company 0x0000000100163cb4 Company.DashboardViewController.collectionView(Company.DashboardViewController)的函数签名专用化(Objective.UICollectionView,cellForItemAtIndexPath:Objective.NSIndexPath)->Objective.UICollectionViewCell(DashboardViewController.swift:567)
5公司0x000000010015f3b8@objc Company.DashboardViewController.collectionView(公司.DashboardViewController)(Objective.UICollectionView,cellForItemAtIndexPath:Objective.NSIndexPath)->Objective.UICollectionViewCell(DashboardViewController.swift)
6 UIKit 0x0000000187650710-[UICollectionView\u createPreparedCellForItemAtIndexPath:with LayoutAttribute:applyAttributes:+284
7 UIKit 0x0000000187c7a850 uu 51-[UICollectionView u viewAnimationsForCurrentUpdate]u block_u调用1381+480
8 UIKit 0x00000001877c5164-[UICollectionView\U viewAnimationsForCurrentUpdate]+2892
9 UIKit 0x0000000187c7b694-[UICollectionView_updateWithItems:tentivelyforreOrdering:+1948
10 UIKit 0x0000000187c79c30-[UICollectionView\u EndItemAnimationWithInvalizationContext:tentiveyForreOrdering:+10120
11 UIKit 0x0000000187c7c988-[UICollectionView\u性能更新:完成:失效上下文:潜在订单:+352
12公司0x000000010016c214公司仪表板视图控制器。((在_59C7F3AF672DD71404DED200B8F15814中获取并填充仪表板)(公司仪表板视图控制器)->()->())(关闭#1)(仪表板视图控制器。swift:370)
13 Company 0x00000001000e1728 Company.BaseNetworkManager。(fetchObject(Company.BaseNetworkManager)->(A.Type,path:Swift.String,method:Company.method,参数:Swift.Optional,errorHandler:Company.NetworkErrorHandler,completion:(Company.SingleNetworkResponse)->(Company.RequestMirror)。(闭包#1)。(结束1)。(结束1)(BaseNetworkManager.swift:219)
14 libdispatch.dylib 0x0000000194e6d994调度调用块和释放+24
15 libdispatch.dylib 0x0000000194e6d954调度客户端调用+16
16 libdispatch.dylib 0x0000000194e7220c_dispatch_main_queue_callback_4CF+1608
17 CoreFoundation 0x0000000182b2b7f8 \uu CFRUNLOOP \u正在为\u主\u调度\u队列\uu12提供服务
18 CoreFoundation 0x0000000182b298a0\uU CFRunLoopRun+1492
19 CoreFoundation 0x0000000182a552d4 CFRunLoopRunSpecific+396
20图形服务0x000000018c4b36fc GSEventRunModal+168
21 UIKit 0x0000000187652f40 UIApplicationMain+1488
22公司0x000000010003ac1c干管(干管m:13)
23 libdyld.dylib 0x0000000194e9aa08启动+4

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

您能详细说明一下吗?代码并不总是崩溃。我无法重现崩溃事件。日志来自崩溃报告工具。崩溃也不在该行,它在下面的行。属性字符串基于Objective-C字符串。Objective-C字符串使用UTF-16。属性字符串的范围必须以UTF-16单位计算字符数。您的代码计算字符串使用的任何单位。崩溃将根据您拥有的字符数以及计数的差异而发生。谢谢,我将进行更改,并查看是否再次发生此崩溃