Home > Software engineering >  Swift - Create CSV file with text/csv MIME type
Swift - Create CSV file with text/csv MIME type

Time:07-26

I'm using the following line in Swift to create a CSV file:
filePathToCSV.write(to: url, atomically: true, encoding: .utf8)

Unfortunately, the file has a MIME type of text/plain. How can I change the MIME type to text/csv?
I've searched high and low for a solution, but haven't found one yet.

Any help is much appreciated. Thank you!

CodePudding user response:

Thank you everyone for your input!

I received some help from the Apple Developer Forums: https://developers.apple.com/forums/thread/710757?page=1#721303022

Changing the line-break characters from \n to \r\n did the trick! The file command now shows the file's MIME type as text\csv.

  • Related