Swift Quick Tips: Multi-Line String Literals (Swift 4)

Photo by: Roman Bozhko, Los Angeles, United States. Source: https://unsplash.com

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 http://beta.json-generator.com to generate fake JSON data for this example. The result JSON looks like:

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

Software Engineer with a decade of experience in software engineering — https://minikin.me

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store