将代码更新为swift 2

时间:2016-01-20 05:48:23

标签: ios swift swift2 rtf

如何将以下代码更新为swift 2我是新的

if($cond) 
{
    $layout = view('master');
}
else 
{
    $layout = view('master2');
}

$page = view('page');
$layout->content = $page; 

return $layout;

1 个答案:

答案 0 :(得分:1)

您必须在 try catch 中使用此代码,如下所示。

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)
    }
}