How to write data to file in Swift

In this example you can see how to write some data to the text file. I am using XCODE playground to test this code

Alternatively you can define the text first and the you can use writeToFile() method