Skip to content

Instantly share code, notes, and snippets.

extension UIResponder {
/// The responder chain from the target responder (self)
/// to the `UIApplication` and the app delegate
var responderChain: [UIResponder] {
var responderChain: [UIResponder] = []
var currentResponder: UIResponder? = self
while currentResponder != nil {
responderChain.append(currentResponder!)
extension UIWindow {
/// Traverse the window's view hierarchy in the same way as the Debug View Hierarchy tool in Xcode.
///
/// `traverseHierarchy` uses Depth First Search (DFS) to traverse the view hierarchy starting in the window. This way the method can traverse all sub-hierarchies in a correct order.
///
/// - parameters:
/// - visitor: The closure executed for every view object in the hierarchy
/// - responder: The view object, `UIView`, `UIViewController`, or `UIWindow` instance.
/// - level: The depth level in the view hierarchy.
func traverseHierarchy(_ visitor: (_ responder: UIResponder, _ level: Int) -> Void) {
extension UIWindow {
/// Print the app's key window hierarchy.
class func printKeyWindowHierarchy() {
UIApplication.shared.keyWindow?.printHierarchy()
}
/// Prints the window's view hierarchy.
func printHierarchy() {
traverseHierarchy { responder, level in
@designatednerd
designatednerd / Resources-en.lproj-Localizable.stringsdict
Last active February 26, 2020 17:32
99 Bottles of Beer On The Playground
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>beers_on_wall</key>
<dict>
<key>NSStringLocalizedFormatKey</key>
<string>%#@beers@</string>
<key>beers</key>
<dict>