更新代码以快速2 [英] Update code to swift 2
本文介绍了更新代码以快速2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何更新以下代码以快速完成2我是新手
How do i update following code to swift 2 i am new
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
推荐答案
您必须在 try catch 中使用此代码,如下所示.
You have to use this code in try catch like below..
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)
}
}
这篇关于更新代码以快速2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文