Skip to content

Instantly share code, notes, and snippets.

@loganmoseley
Last active December 11, 2015 20:17
Show Gist options
  • Save loganmoseley/28dd20178929b24de5ed to your computer and use it in GitHub Desktop.
Save loganmoseley/28dd20178929b24de5ed to your computer and use it in GitHub Desktop.
Concatenate strings in reduce() with shorthand syntax "+"
//
// 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