속성 문자열에 RTF 파일 내용을 읽으려고하지만 attributedText
은 nil
입니다. 왜?RTF 파일을 속성 문자열
if let fileURL = NSBundle.mainBundle().URLForResource(filename, withExtension: "rtf") {
var error: NSError?
if let attributedText = NSAttributedString(fileURL: fileURL, options: [NSDocumentTypeDocumentAttribute:NSRTFDTextDocumentType], documentAttributes: nil, error: &error){
textView.attributedText = attributedText
}
}
UPD는 :. 이제 textView.attributedText = attributedText
에 충돌이 말한다입니다
if let fileURL = NSBundle.mainBundle().URLForResource(filename, withExtension: "rtf") {
var error: NSError?
let attributedText = NSAttributedString(fileURL: fileURL, options: [NSDocumentTypeDocumentAttribute:NSRTFTextDocumentType], documentAttributes: nil, error: &error)
println(error?.localizedDescription)
textView.attributedText = attributedText
}
: fatal error: unexpectedly found nil while unwrapping an Optional value
가 나는 코드를 변경했습니다. 디버거에서 attributedText
이 nil이 아니며 파일의 특성이있는 텍스트가 포함되어 있습니다.
if let attributedText = NSAttributedString(fileURL: fileURL, options: [NSDocumentTypeDocumentAttribute:NSRTFTextDocumentType], documentAttributes: nil, error: &error) {
textView.attributedText = attributedText
}
else if let error = error {
println(error.localizedDescription)
}
무엇'오류를 말하는가 '? – Larme
@Larme 범위가 실행되지 않아서 오류를 읽을 수 없습니다. – Shmidt
'if'를하지 말고'let attributedText'를하고'error'를 읽으십시오. – Larme