2016-11-26 31 views
-3

我完成遷移我的應用程序swift3但是這部分持續高產導致的問題。- [_ SwiftValue unsignedIntegerValue]:無法識別的選擇發送到實例0x608000243d50(LLDB)

override func viewWillAppear(_ animated: Bool) 
{ 
    super.viewWillAppear(animated) 
    self.navigationController?.setNavigationBarHidden(false, animated: animated) 
    self.navigationItem.title = artworkTitle 


    let title = "<center><span style=\"font-size: 17px;font-weight:lighter;font-family:Avenir-Book;\">" + artworkCaption + "</span></center>" 
    artworkImageView.image = UIImage(named: artworkImagePath) 

    artworkCaptionView.attributedText = title.html2AttStr 
} 

重要控制檯零件

- [_ SwiftValue unsignedIntegerValue]:無法識別的選擇發送到實例0x608000243d50 類型的未捕獲的異常終止NSException (LLDB)

extension String 
{ 
    var html2AttStr:NSAttributedString 
    { 
     let contents: NSMutableAttributedString? 



    do { 
     let attrTextStyle = NSMutableParagraphStyle() 
     attrTextStyle.alignment = NSTextAlignment.center 
     contents = try NSMutableAttributedString(data: data(using: String.Encoding.utf8)!, options:[NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute: String.Encoding.utf8], documentAttributes: nil) 
    } catch _ { 
     contents = nil 
    } 

控制檯

0 CoreFoundation      0x000000010b70934b __exceptionPreprocess + 171 
1 libobjc.A.dylib      0x000000010ad7521e objc_exception_throw + 48 
2 CoreFoundation      0x000000010b778f34 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132 
3 CoreFoundation      0x000000010b68ec15 ___forwarding___ + 1013 
4 CoreFoundation      0x000000010b68e798 _CF_forwarding_prep_0 + 120 
5 UIFoundation      0x0000000114565953 -[NSHTMLReader _loadUsingWebKit] + 1329 
6 UIFoundation      0x0000000114566f15 -[NSHTMLReader attributedString] + 22 
7 UIFoundation      0x00000001144fd45c _NSReadAttributedStringFromURLOrData + 5779 
8 UIFoundation      0x00000001144fbd35 -[NSAttributedString(NSAttributedStringUIFoundationAdditions) initWithData:options:documentAttributes:error:] + 115 
9 pg         0x000000010a39fe1d _TTOFCSo25NSMutableAttributedStringcfzT4dataV10Foundation4Data7optionsGVs10DictionarySSP__18documentAttributesGSqGVs33AutoreleasingUnsafeMutablePointerGSqCSo12NSDictionary____S_ + 173 
10 pg         0x000000010a39fba4 _TFCSo25NSMutableAttributedStringCfzT4dataV10Foundation4Data7optionsGVs10DictionarySSP__18documentAttributesGSqGVs33AutoreleasingUnsafeMutablePointerGSqCSo12NSDictionary____S_ + 100 
11 pg         0x000000010a39f96a _TFE2pgSSg11html2AttStrCSo18NSAttributedString + 458 
12 pg         0x000000010a3a901d _TFC2pg21ViewControllerArtwork14viewWillAppearfSbT_ + 1197 
13 pg         0x000000010a3a90b1 _TToFC2pg21ViewControllerArtwork14viewWillAppearfSbT_ + 49 
14 UIKit        0x000000010c642de3 -[UIViewController _setViewAppearState:isAnimating:] + 692 
15 UIKit        0x000000010c6434f3 -[UIViewController __viewWillAppear:] + 147 
16 UIKit        0x000000010c67e1a3 -[UINavigationController _startTransition:fromViewController:toViewController:] + 890 
17 UIKit        0x000000010c67f0b9 -[UINavigationController _startDeferredTransitionIfNeeded:] + 874 
18 UIKit        0x000000010c68019b -[UINavigationController __viewWillLayoutSubviews] + 58 
19 UIKit        0x000000010c8771b7 -[UILayoutContainerView layoutSubviews] + 223 
20 UIKit        0x000000010c560344 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1237 
21 QuartzCore       0x000000010c312cdc -[CALayer layoutSublayers] + 146 
22 QuartzCore       0x000000010c3067a0 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366 
23 QuartzCore       0x000000010c30661e _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24 
24 QuartzCore       0x000000010c29462c _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 280 
25 QuartzCore       0x000000010c2c1713 _ZN2CA11Transaction6commitEv + 475 
26 UIKit        0x000000010c495067 _UIApplicationFlushRunLoopCATransactionIfTooLate + 206 
27 UIKit        0x000000010cca4b30 __handleEventQueue + 5672 
28 CoreFoundation      0x000000010b6ae311 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17 
29 CoreFoundation      0x000000010b69359c __CFRunLoopDoSources0 + 556 
30 CoreFoundation      0x000000010b692a86 __CFRunLoopRun + 918 
31 CoreFoundation      0x000000010b692494 CFRunLoopRunSpecific + 420 
32 GraphicsServices     0x0000000111084a6f GSEventRunModal + 161 
33 UIKit        0x000000010c49bf34 UIApplicationMain + 159 
34 pg         0x000000010a3acaaf main + 111 
35 libdyld.dylib      0x000000011233668d start + 1 
36 ???         0x0000000000000001 0x0 + 1 

的libC++ abi.dylib:與類型NSException的未捕獲的異常終止

+1

更換NSCharacterEncodingDocumentAttribute: String.Encoding.utf8如果你的代碼與我們分享,請不要發佈它作爲圖像。你可以把它添加到您的帖子,[格式設置爲代碼(http://stackoverflow.com/editing-help#code)。 – FelixSFD

+0

和發佈所有相關的代碼,這是很難說這是怎麼回事就沒有更多的上下文 – Miknash

+0

郵政'html2AttStr'擴展的代碼。似乎在那裏。 –

回答

5

我記得reading on Apple's Swift blog,如果你無法識別的選擇錯誤,這意味着斯威夫特結構的自動包裝是導致的問題。最有可能的是包裝String.Encoding,而不是將其轉換爲NSNumber(背後是什麼在NSMutableAttributedString Objective-C代碼期待)的。

嘗試用NSCharacterEncodingDocumentAttribute: String.Encoding.utf8.rawValue

相關問題