问题
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
回答1:
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)
}
}
来源:https://stackoverflow.com/questions/34892434/update-code-to-swift-2