String

extension String
  • Returns a SourceFile containing self, a multiline string literal, such that diagnostics produced in processing that file will point back to the original Swift source.

    The text of the result will literally be what’s in the Swift file, including its indentation and any embedded special characters, even if the literal itself is not a raw literal or has had indentation stripped by the Swift compiler. It is assumed that this function is invoked on the line containing the closing quotation marks, e.g.

    let f = """
       let x = 1
    """.asSourceFile()
    

    Warning

    • Only use this function with multiline string literals.
    • Write .asSourceFile() on the same line as the close quotation marks.
    • Serialization of the result is not supported.

    Declaration

    Swift

    public func asSourceFile(swiftFile: String = #filePath, invocationLine: Int = #line) -> SourceFile