2016-01-20 49 views
-3

如何更新下面的代碼來迅速2我是新更新代碼SWIFT 2

if let rtf = NSBundle.mainBundle().URLForResource("rtfdoc", withExtension: "rtf", subdirectory: nil, localization: nil) { 

     let attributedString = NSAttributedString(fileURL: rtf, options: [NSDocumentTypeDocumentAttribute:NSRTFTextDocumentType], documentAttributes: nil, error: nil) 
     textView.attributedText = attributedString 
     textView.editable = false 

回答

1

你有嘗試捕捉像下面使用此代碼..

if let rtf = NSBundle.mainBundle().URLForResource("rtfdoc", withExtension: "rtf") { 
    do { 
     let attributedString = try NSAttributedString(fileURL: rtf, options: [NSDocumentTypeDocumentAttribute:NSRTFTextDocumentType], documentAttributes: nil) 
     textView.attributedText = attributedString 
     textView.editable = false 
     print(attributedString) 
    } catch let error as NSError { 
     print(error.localizedDescription) 
    } 
}