Last active
December 11, 2015 20:17
-
-
Save loganmoseley/28dd20178929b24de5ed to your computer and use it in GitHub Desktop.
Concatenate strings in reduce() with shorthand syntax "+"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// UIView+RecursiveDescription.swift | |
// | |
// Created by Logan Moseley on 12/11/15. | |
// | |
import UIKit | |
extension UIView { | |
var recursiveDescription: String { | |
return indentedRecursiveDescription("") | |
} | |
private func indentedRecursiveDescription(currentIndentation: String) -> String { | |
let myDescription = "\(self.indentedDescriptionLine(currentIndentation))\n" | |
let newIndentation = currentIndentation.stringByAppendingString(" ") | |
let subviewDescriptions = subviews.map { $0.indentedRecursiveDescription(newIndentation) } | |
return subviewDescriptions.reduce(myDescription, combine: +) | |
} | |
private func indentedDescriptionLine(indentation: String) -> String { | |
return indentation.stringByAppendingString(self.description) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment