Multi-Line String Literals

June 2, 2017 - 1 minute read -
ios swift

Only a few days left before WWDC 2017. I hope that we’ll see a lot of great and useful stuff, besides Swift 4, from Apple which can help us to make the world a better place.

One of the exciting features of upcoming Swift 4 is Multi-Line String Literals. I often need a quick way to create a prototype app with JSON data. Usually, I need to save data to local JSON file and then read from file or use network layer. That takes time. In Swift 4 we can use [Multi-Line String Literals]( 

Example:  I used to generate fake JSON data for this example. The result JSON looks like: JSON sample.json

Previously it wasn’t possible to use such strings like string literals. In Swift 4 you can just copy/past it like this:

""" JSON/XML/OTHERS COMPLEX STRINGS """ Multi-Line String Literals.playground Multi-Line String Literals.playground