2016-01-20 51 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) 
    } 
}