Update code to swift 2 [closed]

江枫思渺然 提交于 2019-12-13 11:21:21

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!