title: Read text from all rtf files in directory and create master file swift
body: <p><strong>Context</strong>
  I have an app where the user can write multiple 'scenes'. These are saved as separate file. I need to offer the user 2 options for exporting (to export all scenes individually or all together in one master file). </p>
  
  <p><strong>What am I try to do</strong> My approach at the moment is to try retrieve the URLs of each file with the extension of .rtf. Then to loop through each, extracting the NSAttributedString. Finally I plan on writing each in turn to a master .rtf file. </p>
  
  <p><strong>What have I tried</strong> Using ideas from various other answers (e.g. <a href="https://stackoverflow.com/questions/41656808/swift-merge-files">here</a> and <a href="https://stackoverflow.com/questions/27327067/append-text-or-data-to-text-file-in-swift">here</a> on similar issues I am trying the below which I've annotated to make clear. Needless to say I am a bit stuck and lost for what to do next :</p>
  
  <pre><code>@IBAction func exportPressed(_ sender: Any) {
          //THIS BIT RETRIEVES THE URLS OF EACH .RTF FILE AND PUTS THEM INTO AN ARRAY CALLED SCENEURLS. THIS BIT WORKS FINE AND I'VE TESTED BY PRINTING OUT A LIST OF THE URLS.
  
          do {
              let documentsURL = getDocumentDirectory()
              let docs = try FileManager.default.contentsOfDirectory(at: documentsURL, includingPropertiesForKeys: [], options:  [.skipsHiddenFiles, .skipsSubdirectoryDescendants])
              let scenesURLs = docs.filter{ $0.pathExtension == "rtf" }
  
  //THIS BIT TRYS TO RETURN THE NSATTRIBUTEDSTRING FOR EACH OF THE SCENE URLS. THIS BIT THROWS UP MULTIPLE ERRORS. I SUPPOSE I WOULD WANT TO ADD THE STRINGS TO A NEW ARRAY [SCENETEXTSTRINGS] SO I COULD THEN LOOP THROUGH THAT AND WRITE THE NEW MASTER FILE WITH TEXT FROM EACH IN THE RIGHT ORDER.
  
              scenesURLs.forEach {_ in
  
                  return try NSAttributedString()(url: scenesURLs(),
                                                  options: [.documentType: NSAttributedString.DocumentType.rtf],
                                                  documentAttributes: nil)
              } catch {
  
                  print("failed to populate text view with current scene with error: \(error)")
  
                  return nil
              }
              }
          } catch {
              print(error)
          }
  
  //THERE NEEDS TO BE SOMETHING HERE THAT THEN WRITES THE STRINGS IN THE NEW STRINGS ARRAY TO A NEW MASTER FILE
      }
  </code></pre>
  
  <p>To start with, I just need some help with how to get the strings in an array - I can try work out writing the new master after that!</p>