3

私はXcode 9に更新し、swift 3からswift 4にマイアプリを変換してこのエラーを取得しました。どのように私はこれを修正することができます?'NSAttributedString.DocumentAttributeKey'型の値を予想される辞書キータイプ 'NSAttributedString.DocumentReadingOptionKey'に変換できません

func displayText() { 
    do { 
     if url.pathExtension.lowercased() != "rtf" { 
      let fileContent = try String(contentsOf: url) 
      text.text = fileContent 
     } else { // Is RTF file 
      let attributedString = try NSAttributedString(url: url, options: [NSDocumentTypeDocumentAttribute:NSRTFTextDocumentType], documentAttributes: nil) 
      text.attributedText = attributedString 
      text.isEditable = false 
     } 
    } 

、このエラーを取得

型の値が期待辞書のキータイプに 'NSAttributedString.DocumentAttributeKey' 'NSAttributedString.DocumentReadingOptionKey'

迅速4では

答えて

2

変換できません - NSAttributedStringを表現は完全に変更されます。

これを試してみてください[NSAttributedString.DocumentReadingOptionKey.documentType : NSAttributedString.DocumentType.rtf]

であなたの属性辞書のキーと値[NSDocumentTypeDocumentAttribute:NSRTFTextDocumentType]を置き換えますNSAttributedString - Creating an NSAttributedString Object

:ここ

func displayText() { 
    do { 
     if url.pathExtension.lowercased() != "rtf" { 
      let fileContent = try String(contentsOf: url) 
      text.text = fileContent 
     } else { // Is RTF file 
      let attributedString = try NSAttributedString(url: url, options: [NSAttributedString.DocumentReadingOptionKey.documentType : NSAttributedString.DocumentType.rtf], documentAttributes: nil) 
      text.attributedText = attributedString 
      text.isEditable = false 
     } 
    } 
} 

は、Appleからのノートです

関連する問題