-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathComputedLayout+CustomStringConvertible.swift
61 lines (47 loc) · 1.72 KB
/
ComputedLayout+CustomStringConvertible.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//
// ComputedLayout+CustomStringConvertible.swift
// Steward
//
// Created by Jake Marsh on 10/2/16.
// Copyright © 2016 Magnus. All rights reserved.
//
import Foundation
extension ComputedLayout: CustomStringConvertible {
public var description: String {
return description(forDepth: 0)
}
public var debugDescription: String {
return description(forDepth: 0)
}
private func description(forDepth depth: Int) -> String {
let tab = " " // "\t"
let indentation = depth == 0 ? "" : (0...depth).reduce("") { accum, _ in accum + tab }
var d = ""
d += indentation + "ComputedLayout("
if children.count > 0 {
d += "\n" + indentation
d += tab
}
d += "frame: CGRect(x: \(frame.origin.x), y: \(frame.origin.y), width: \(frame.size.width), height: \(frame.size.height))"
if children.count > 0 {
d += ",\n\(indentation + tab)children: ["
d += "\n" + (indentation) + (children.map { $0.description(forDepth: depth + 1) }).joined(separator: ",\n" + indentation)
d += "\n\(indentation + tab)]"
d += "\n\(indentation))"
} else {
d += ")"
}
return d
}
// private func description(forDepth depth: Int) -> String {
// let selfDescription = "{origin={\(frame.origin.x), \(frame.origin.y)}, size={\(frame.size.width), \(frame.size.height)}}"
//
// if children.count > 0 {
// let indentation = (0...depth).reduce("\n") { accum, _ in accum + "\t" }
// let childrenDescription = (children.map { $0.description(forDepth: depth + 1) }).joined(separator: indentation)
// return "\(selfDescription)\(indentation)\(childrenDescription)"
// } else {
// return selfDescription
// }
// }
}