DefaultStringInterpolation
EXTENSION
DefaultStringInterpolation
Swift
1public extension DefaultStringInterpolation
Methods
appendInterpolation(indented:)
Swift
1mutating func appendInterpolation(indented string: String)
A String interpolation function that respects nested indentation.
Example:
Swift
1class Root {
2let children: [Root] = []
3func description: String {
4 var desc = "\(type(of: self)) {"
5 children.forEach { child in
6 desc += "\n \(indented: child.debugDescription),"
7 }
8 if !children.isEmpty { desc += "\n" }
9 desc += "\(indented: "}")"
10 return desc
11}
12// Given classes A - E as subclasses of Root
13
14let root = Root(children: [A(children: [B(), C(children: [D()])]), E()])
15print(root.description)
This prints: Root { A { B {} C { D {} } } E {} }