I am reading the JavaScriptCore article. In the article there is the following expression,
context.evaluateScript(#"""
function triple(number) {
return number * 3;
}
"""#)
Three double quotes are used to delineate a multi-line string in Swift. My question is the hashtag usage at the beginning and end of the multi-line string expression.
Is there a specific name for this and its usage? Is a multi-line string in an instance method generally delineated by hashtags? Is there a general discussion somewhere as to when and where hashtags are employed in Swift?
Thanks!
Karl
(👑🦆)
December 9, 2019, 4:08pm
2
It’s a raw string literal. See: How to use raw strings in Swift 5 – Hacking with Swift
The full proposal can be found here:
# Enhancing String Literals Delimiters to Support Raw Text
* Proposal: [SE-0200](0200-raw-string-escaping.md)
* Authors: [John Holdsworth](https://github.com/johnno1962), [Brent Royal-Gordon](https://github.com/brentdax), [Erica Sadun](https://github.com/erica)
* Review Manager: [Doug Gregor](https://github.com/DougGregor)
* Previous Revision: [1](https://github.com/apple/swift-evolution/blob/102b2f2770f0dab29f254a254063847388647a4a/proposals/0200-raw-string-escaping.md)
* Status: **Implemented (Swift 5)**
* Implementation: [apple/swift#17668](https://github.com/apple/swift/pull/17668)
* Bugs: [SR-6362](https://bugs.swift.org/browse/SR-6362)
* Review: [Discussion thread](https://forums.swift.org/t/se-0200-enhancing-string-literals-delimiters-to-support-raw-text/15420), [Announcement thread](https://forums.swift.org/t/accepted-se-0200-enhancing-string-literals-delimiters-to-support-raw-text/15822/2)
## Introduction
Like many computer languages, Swift uses an escape character (`\`) to create a special interpretation of subsequent characters within a string literal. Escape character sequences represent a set of predefined, non-printing characters as well as string delimiters (the double quote), the escape character (the backslash itself), and (uniquely in Swift) to allow in-string expression interpolation.
Escape characters provide useful and necessary capabilities but strings containing many escape sequences are difficult to read. Other languages have solved this problem by providing an alternate "raw" string literal syntax which does not process escape sequences. As the name suggests, raw string literals allow you to use "raw" text, incorporating backslashes and double quotes without escaping.
We propose to alter Swift's string literal design to do the same, using a new design which we believe fits Swift's simple and clean syntax. This design supports both single-line and multi-line string literals, and can contain any content whatsoever.
This proposal has been extensively revised based on the Core Team feedback for [SE-0200](https://forums.swift.org/t/returned-for-revision-se-0200-raw-mode-string-literals/11630). It was discussed on the [Swift online forums](https://forums.swift.org/t/pure-bikeshedding-raw-strings-why-yes-again/13866).
This file has been truncated. show original
2 Likes
Thanks Karl!
I should have used the phrase pound sign instead of hashtag or the literal # when I searched.