├── .gitignore ├── Example ├── Example.xcodeproj │ ├── project.pbxproj │ └── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ └── IDEWorkspaceChecks.plist └── Example │ ├── Assets.xcassets │ ├── AccentColor.colorset │ │ └── Contents.json │ ├── AppIcon.appiconset │ │ └── Contents.json │ └── Contents.json │ ├── ContentView.swift │ ├── ExampleApp.swift │ └── Preview Content │ └── Preview Assets.xcassets │ └── Contents.json ├── LICENSE ├── README.md ├── Resources ├── example1.png ├── example2.png ├── video.gif └── video2.gif ├── TreeDumpDebugger.swift └── tdump.py /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## User settings 6 | xcuserdata/ 7 | 8 | ## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9) 9 | *.xcscmblueprint 10 | *.xccheckout 11 | 12 | ## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4) 13 | build/ 14 | DerivedData/ 15 | *.moved-aside 16 | *.pbxuser 17 | !default.pbxuser 18 | *.mode1v3 19 | !default.mode1v3 20 | *.mode2v3 21 | !default.mode2v3 22 | *.perspectivev3 23 | !default.perspectivev3 24 | 25 | ## Obj-C/Swift specific 26 | *.hmap 27 | 28 | ## App packaging 29 | *.ipa 30 | *.dSYM.zip 31 | *.dSYM 32 | 33 | ## Playgrounds 34 | timeline.xctimeline 35 | playground.xcworkspace 36 | 37 | # Swift Package Manager 38 | # 39 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. 40 | # Packages/ 41 | # Package.pins 42 | # Package.resolved 43 | # *.xcodeproj 44 | # 45 | # Xcode automatically generates this directory with a .xcworkspacedata file and xcuserdata 46 | # hence it is not needed unless you have added a package configuration file to your project 47 | # .swiftpm 48 | 49 | .build/ 50 | 51 | *.DS_Store 52 | 53 | # CocoaPods 54 | # 55 | # We recommend against adding the Pods directory to your .gitignore. However 56 | # you should judge for yourself, the pros and cons are mentioned at: 57 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 58 | # 59 | # Pods/ 60 | # 61 | # Add this line if you want to avoid checking in source code from the Xcode workspace 62 | # *.xcworkspace 63 | 64 | # Carthage 65 | # 66 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 67 | # Carthage/Checkouts 68 | 69 | Carthage/Build/ 70 | 71 | # Accio dependency management 72 | Dependencies/ 73 | .accio/ 74 | 75 | # fastlane 76 | # 77 | # It is recommended to not store the screenshots in the git repo. 78 | # Instead, use fastlane to re-generate the screenshots whenever they are needed. 79 | # For more information about the recommended setup visit: 80 | # https://docs.fastlane.tools/best-practices/source-control/#source-control 81 | 82 | fastlane/report.xml 83 | fastlane/Preview.html 84 | fastlane/screenshots/**/*.png 85 | fastlane/test_output 86 | 87 | # Code Injection 88 | # 89 | # After new code Injection tools there's a generated folder /iOSInjectionProject 90 | # https://github.com/johnno1962/injectionforxcode 91 | 92 | iOSInjectionProject/ 93 | -------------------------------------------------------------------------------- /Example/Example.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 55; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | AB6706D5278D90AB00D9224E /* ExampleApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB6706D4278D90AB00D9224E /* ExampleApp.swift */; }; 11 | AB6706D7278D90AB00D9224E /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB6706D6278D90AB00D9224E /* ContentView.swift */; }; 12 | AB6706D9278D90AC00D9224E /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = AB6706D8278D90AC00D9224E /* Assets.xcassets */; }; 13 | AB6706DC278D90AC00D9224E /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = AB6706DB278D90AC00D9224E /* Preview Assets.xcassets */; }; 14 | AB6706E5278D90CB00D9224E /* TreeDumpDebugger.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB6706E4278D90CB00D9224E /* TreeDumpDebugger.swift */; }; 15 | /* End PBXBuildFile section */ 16 | 17 | /* Begin PBXFileReference section */ 18 | AB6706D1278D90AB00D9224E /* Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Example.app; sourceTree = BUILT_PRODUCTS_DIR; }; 19 | AB6706D4278D90AB00D9224E /* ExampleApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExampleApp.swift; sourceTree = ""; }; 20 | AB6706D6278D90AB00D9224E /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; 21 | AB6706D8278D90AC00D9224E /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 22 | AB6706DB278D90AC00D9224E /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = ""; }; 23 | AB6706E4278D90CB00D9224E /* TreeDumpDebugger.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = TreeDumpDebugger.swift; path = ../../TreeDumpDebugger.swift; sourceTree = ""; }; 24 | /* End PBXFileReference section */ 25 | 26 | /* Begin PBXFrameworksBuildPhase section */ 27 | AB6706CE278D90AB00D9224E /* Frameworks */ = { 28 | isa = PBXFrameworksBuildPhase; 29 | buildActionMask = 2147483647; 30 | files = ( 31 | ); 32 | runOnlyForDeploymentPostprocessing = 0; 33 | }; 34 | /* End PBXFrameworksBuildPhase section */ 35 | 36 | /* Begin PBXGroup section */ 37 | AB6706C8278D90AB00D9224E = { 38 | isa = PBXGroup; 39 | children = ( 40 | AB6706D3278D90AB00D9224E /* Example */, 41 | AB6706D2278D90AB00D9224E /* Products */, 42 | ); 43 | sourceTree = ""; 44 | }; 45 | AB6706D2278D90AB00D9224E /* Products */ = { 46 | isa = PBXGroup; 47 | children = ( 48 | AB6706D1278D90AB00D9224E /* Example.app */, 49 | ); 50 | name = Products; 51 | sourceTree = ""; 52 | }; 53 | AB6706D3278D90AB00D9224E /* Example */ = { 54 | isa = PBXGroup; 55 | children = ( 56 | AB6706E4278D90CB00D9224E /* TreeDumpDebugger.swift */, 57 | AB6706D4278D90AB00D9224E /* ExampleApp.swift */, 58 | AB6706D6278D90AB00D9224E /* ContentView.swift */, 59 | AB6706D8278D90AC00D9224E /* Assets.xcassets */, 60 | AB6706DA278D90AC00D9224E /* Preview Content */, 61 | ); 62 | path = Example; 63 | sourceTree = ""; 64 | }; 65 | AB6706DA278D90AC00D9224E /* Preview Content */ = { 66 | isa = PBXGroup; 67 | children = ( 68 | AB6706DB278D90AC00D9224E /* Preview Assets.xcassets */, 69 | ); 70 | path = "Preview Content"; 71 | sourceTree = ""; 72 | }; 73 | /* End PBXGroup section */ 74 | 75 | /* Begin PBXNativeTarget section */ 76 | AB6706D0278D90AB00D9224E /* Example */ = { 77 | isa = PBXNativeTarget; 78 | buildConfigurationList = AB6706DF278D90AC00D9224E /* Build configuration list for PBXNativeTarget "Example" */; 79 | buildPhases = ( 80 | AB6706CD278D90AB00D9224E /* Sources */, 81 | AB6706CE278D90AB00D9224E /* Frameworks */, 82 | AB6706CF278D90AB00D9224E /* Resources */, 83 | ); 84 | buildRules = ( 85 | ); 86 | dependencies = ( 87 | ); 88 | name = Example; 89 | productName = Example; 90 | productReference = AB6706D1278D90AB00D9224E /* Example.app */; 91 | productType = "com.apple.product-type.application"; 92 | }; 93 | /* End PBXNativeTarget section */ 94 | 95 | /* Begin PBXProject section */ 96 | AB6706C9278D90AB00D9224E /* Project object */ = { 97 | isa = PBXProject; 98 | attributes = { 99 | BuildIndependentTargetsInParallel = 1; 100 | LastSwiftUpdateCheck = 1310; 101 | LastUpgradeCheck = 1310; 102 | TargetAttributes = { 103 | AB6706D0278D90AB00D9224E = { 104 | CreatedOnToolsVersion = 13.1; 105 | }; 106 | }; 107 | }; 108 | buildConfigurationList = AB6706CC278D90AB00D9224E /* Build configuration list for PBXProject "Example" */; 109 | compatibilityVersion = "Xcode 13.0"; 110 | developmentRegion = en; 111 | hasScannedForEncodings = 0; 112 | knownRegions = ( 113 | en, 114 | Base, 115 | ); 116 | mainGroup = AB6706C8278D90AB00D9224E; 117 | productRefGroup = AB6706D2278D90AB00D9224E /* Products */; 118 | projectDirPath = ""; 119 | projectRoot = ""; 120 | targets = ( 121 | AB6706D0278D90AB00D9224E /* Example */, 122 | ); 123 | }; 124 | /* End PBXProject section */ 125 | 126 | /* Begin PBXResourcesBuildPhase section */ 127 | AB6706CF278D90AB00D9224E /* Resources */ = { 128 | isa = PBXResourcesBuildPhase; 129 | buildActionMask = 2147483647; 130 | files = ( 131 | AB6706DC278D90AC00D9224E /* Preview Assets.xcassets in Resources */, 132 | AB6706D9278D90AC00D9224E /* Assets.xcassets in Resources */, 133 | ); 134 | runOnlyForDeploymentPostprocessing = 0; 135 | }; 136 | /* End PBXResourcesBuildPhase section */ 137 | 138 | /* Begin PBXSourcesBuildPhase section */ 139 | AB6706CD278D90AB00D9224E /* Sources */ = { 140 | isa = PBXSourcesBuildPhase; 141 | buildActionMask = 2147483647; 142 | files = ( 143 | AB6706E5278D90CB00D9224E /* TreeDumpDebugger.swift in Sources */, 144 | AB6706D7278D90AB00D9224E /* ContentView.swift in Sources */, 145 | AB6706D5278D90AB00D9224E /* ExampleApp.swift in Sources */, 146 | ); 147 | runOnlyForDeploymentPostprocessing = 0; 148 | }; 149 | /* End PBXSourcesBuildPhase section */ 150 | 151 | /* Begin XCBuildConfiguration section */ 152 | AB6706DD278D90AC00D9224E /* Debug */ = { 153 | isa = XCBuildConfiguration; 154 | buildSettings = { 155 | ALWAYS_SEARCH_USER_PATHS = NO; 156 | CLANG_ANALYZER_NONNULL = YES; 157 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 158 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++17"; 159 | CLANG_CXX_LIBRARY = "libc++"; 160 | CLANG_ENABLE_MODULES = YES; 161 | CLANG_ENABLE_OBJC_ARC = YES; 162 | CLANG_ENABLE_OBJC_WEAK = YES; 163 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 164 | CLANG_WARN_BOOL_CONVERSION = YES; 165 | CLANG_WARN_COMMA = YES; 166 | CLANG_WARN_CONSTANT_CONVERSION = YES; 167 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 168 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 169 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 170 | CLANG_WARN_EMPTY_BODY = YES; 171 | CLANG_WARN_ENUM_CONVERSION = YES; 172 | CLANG_WARN_INFINITE_RECURSION = YES; 173 | CLANG_WARN_INT_CONVERSION = YES; 174 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 175 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 176 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 177 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 178 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 179 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 180 | CLANG_WARN_STRICT_PROTOTYPES = YES; 181 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 182 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 183 | CLANG_WARN_UNREACHABLE_CODE = YES; 184 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 185 | COPY_PHASE_STRIP = NO; 186 | DEBUG_INFORMATION_FORMAT = dwarf; 187 | ENABLE_STRICT_OBJC_MSGSEND = YES; 188 | ENABLE_TESTABILITY = YES; 189 | GCC_C_LANGUAGE_STANDARD = gnu11; 190 | GCC_DYNAMIC_NO_PIC = NO; 191 | GCC_NO_COMMON_BLOCKS = YES; 192 | GCC_OPTIMIZATION_LEVEL = 0; 193 | GCC_PREPROCESSOR_DEFINITIONS = ( 194 | "DEBUG=1", 195 | "$(inherited)", 196 | ); 197 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 198 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 199 | GCC_WARN_UNDECLARED_SELECTOR = YES; 200 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 201 | GCC_WARN_UNUSED_FUNCTION = YES; 202 | GCC_WARN_UNUSED_VARIABLE = YES; 203 | IPHONEOS_DEPLOYMENT_TARGET = 15.0; 204 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 205 | MTL_FAST_MATH = YES; 206 | ONLY_ACTIVE_ARCH = YES; 207 | SDKROOT = iphoneos; 208 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 209 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 210 | }; 211 | name = Debug; 212 | }; 213 | AB6706DE278D90AC00D9224E /* Release */ = { 214 | isa = XCBuildConfiguration; 215 | buildSettings = { 216 | ALWAYS_SEARCH_USER_PATHS = NO; 217 | CLANG_ANALYZER_NONNULL = YES; 218 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 219 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++17"; 220 | CLANG_CXX_LIBRARY = "libc++"; 221 | CLANG_ENABLE_MODULES = YES; 222 | CLANG_ENABLE_OBJC_ARC = YES; 223 | CLANG_ENABLE_OBJC_WEAK = YES; 224 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 225 | CLANG_WARN_BOOL_CONVERSION = YES; 226 | CLANG_WARN_COMMA = YES; 227 | CLANG_WARN_CONSTANT_CONVERSION = YES; 228 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 229 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 230 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 231 | CLANG_WARN_EMPTY_BODY = YES; 232 | CLANG_WARN_ENUM_CONVERSION = YES; 233 | CLANG_WARN_INFINITE_RECURSION = YES; 234 | CLANG_WARN_INT_CONVERSION = YES; 235 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 236 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 237 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 238 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 239 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 240 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 241 | CLANG_WARN_STRICT_PROTOTYPES = YES; 242 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 243 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 244 | CLANG_WARN_UNREACHABLE_CODE = YES; 245 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 246 | COPY_PHASE_STRIP = NO; 247 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 248 | ENABLE_NS_ASSERTIONS = NO; 249 | ENABLE_STRICT_OBJC_MSGSEND = YES; 250 | GCC_C_LANGUAGE_STANDARD = gnu11; 251 | GCC_NO_COMMON_BLOCKS = YES; 252 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 253 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 254 | GCC_WARN_UNDECLARED_SELECTOR = YES; 255 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 256 | GCC_WARN_UNUSED_FUNCTION = YES; 257 | GCC_WARN_UNUSED_VARIABLE = YES; 258 | IPHONEOS_DEPLOYMENT_TARGET = 15.0; 259 | MTL_ENABLE_DEBUG_INFO = NO; 260 | MTL_FAST_MATH = YES; 261 | SDKROOT = iphoneos; 262 | SWIFT_COMPILATION_MODE = wholemodule; 263 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 264 | VALIDATE_PRODUCT = YES; 265 | }; 266 | name = Release; 267 | }; 268 | AB6706E0278D90AC00D9224E /* Debug */ = { 269 | isa = XCBuildConfiguration; 270 | buildSettings = { 271 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 272 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; 273 | CODE_SIGN_STYLE = Automatic; 274 | CURRENT_PROJECT_VERSION = 1; 275 | DEVELOPMENT_ASSET_PATHS = "\"Example/Preview Content\""; 276 | DEVELOPMENT_TEAM = VPKMBVYVNK; 277 | ENABLE_PREVIEWS = YES; 278 | GENERATE_INFOPLIST_FILE = YES; 279 | INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; 280 | INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; 281 | INFOPLIST_KEY_UILaunchScreen_Generation = YES; 282 | INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; 283 | INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; 284 | LD_RUNPATH_SEARCH_PATHS = ( 285 | "$(inherited)", 286 | "@executable_path/Frameworks", 287 | ); 288 | MARKETING_VERSION = 1.0; 289 | PRODUCT_BUNDLE_IDENTIFIER = com.johanthorell.com.Example; 290 | PRODUCT_NAME = "$(TARGET_NAME)"; 291 | SWIFT_EMIT_LOC_STRINGS = YES; 292 | SWIFT_VERSION = 5.0; 293 | TARGETED_DEVICE_FAMILY = "1,2"; 294 | }; 295 | name = Debug; 296 | }; 297 | AB6706E1278D90AC00D9224E /* Release */ = { 298 | isa = XCBuildConfiguration; 299 | buildSettings = { 300 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 301 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; 302 | CODE_SIGN_STYLE = Automatic; 303 | CURRENT_PROJECT_VERSION = 1; 304 | DEVELOPMENT_ASSET_PATHS = "\"Example/Preview Content\""; 305 | DEVELOPMENT_TEAM = VPKMBVYVNK; 306 | ENABLE_PREVIEWS = YES; 307 | GENERATE_INFOPLIST_FILE = YES; 308 | INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; 309 | INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; 310 | INFOPLIST_KEY_UILaunchScreen_Generation = YES; 311 | INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; 312 | INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; 313 | LD_RUNPATH_SEARCH_PATHS = ( 314 | "$(inherited)", 315 | "@executable_path/Frameworks", 316 | ); 317 | MARKETING_VERSION = 1.0; 318 | PRODUCT_BUNDLE_IDENTIFIER = com.johanthorell.com.Example; 319 | PRODUCT_NAME = "$(TARGET_NAME)"; 320 | SWIFT_EMIT_LOC_STRINGS = YES; 321 | SWIFT_VERSION = 5.0; 322 | TARGETED_DEVICE_FAMILY = "1,2"; 323 | }; 324 | name = Release; 325 | }; 326 | /* End XCBuildConfiguration section */ 327 | 328 | /* Begin XCConfigurationList section */ 329 | AB6706CC278D90AB00D9224E /* Build configuration list for PBXProject "Example" */ = { 330 | isa = XCConfigurationList; 331 | buildConfigurations = ( 332 | AB6706DD278D90AC00D9224E /* Debug */, 333 | AB6706DE278D90AC00D9224E /* Release */, 334 | ); 335 | defaultConfigurationIsVisible = 0; 336 | defaultConfigurationName = Release; 337 | }; 338 | AB6706DF278D90AC00D9224E /* Build configuration list for PBXNativeTarget "Example" */ = { 339 | isa = XCConfigurationList; 340 | buildConfigurations = ( 341 | AB6706E0278D90AC00D9224E /* Debug */, 342 | AB6706E1278D90AC00D9224E /* Release */, 343 | ); 344 | defaultConfigurationIsVisible = 0; 345 | defaultConfigurationName = Release; 346 | }; 347 | /* End XCConfigurationList section */ 348 | }; 349 | rootObject = AB6706C9278D90AB00D9224E /* Project object */; 350 | } 351 | -------------------------------------------------------------------------------- /Example/Example.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Example/Example.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Example/Example/Assets.xcassets/AccentColor.colorset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "colors" : [ 3 | { 4 | "idiom" : "universal" 5 | } 6 | ], 7 | "info" : { 8 | "author" : "xcode", 9 | "version" : 1 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Example/Example/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "scale" : "2x", 6 | "size" : "20x20" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "scale" : "3x", 11 | "size" : "20x20" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "scale" : "2x", 16 | "size" : "29x29" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "scale" : "3x", 21 | "size" : "29x29" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "scale" : "2x", 26 | "size" : "40x40" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "scale" : "3x", 31 | "size" : "40x40" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "scale" : "2x", 36 | "size" : "60x60" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "scale" : "3x", 41 | "size" : "60x60" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "scale" : "1x", 46 | "size" : "20x20" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "scale" : "2x", 51 | "size" : "20x20" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "scale" : "1x", 56 | "size" : "29x29" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "scale" : "2x", 61 | "size" : "29x29" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "scale" : "1x", 66 | "size" : "40x40" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "scale" : "2x", 71 | "size" : "40x40" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "scale" : "1x", 76 | "size" : "76x76" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "scale" : "2x", 81 | "size" : "76x76" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "scale" : "2x", 86 | "size" : "83.5x83.5" 87 | }, 88 | { 89 | "idiom" : "ios-marketing", 90 | "scale" : "1x", 91 | "size" : "1024x1024" 92 | } 93 | ], 94 | "info" : { 95 | "author" : "xcode", 96 | "version" : 1 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /Example/Example/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /Example/Example/ContentView.swift: -------------------------------------------------------------------------------- 1 | /** 2 | * Tree Dump Debugger 3 | * Copyright (c) Johan Thorell 2022 4 | * MIT license, see LICENSE file for details 5 | */ 6 | 7 | import SwiftUI 8 | 9 | struct ContentView: View { 10 | enum Examples: String, CaseIterable { 11 | case present = "Present on key window" 12 | case swiftUI = "Present as SwiftUI modal" 13 | } 14 | 15 | @State var showSwiftUIModal = false 16 | 17 | var body: some View { 18 | NavigationView { 19 | List(Examples.allCases, id: \.self) { example in 20 | switch example { 21 | case .present: 22 | Button(example.rawValue) { 23 | TreeDumpDebugger.present(TreeDumpDebugger.SwiftDump(value: exampleData)) 24 | } 25 | case .swiftUI: 26 | Button(example.rawValue) { 27 | showSwiftUIModal = true 28 | }.sheet(isPresented: $showSwiftUIModal) { 29 | TreeDumpDebugger.makeSwiftUIView(with: ["foo": "bar", 122: [122, 45, 4]]) 30 | } 31 | } 32 | } 33 | .navigationTitle("Examples") 34 | } 35 | } 36 | } 37 | 38 | class TestC { 39 | internal init(foo: Int) { 40 | self.foo = foo 41 | } 42 | let foo: Int 43 | } 44 | struct TestB { 45 | var number: Int 46 | var c: TestC 47 | } 48 | class TestA { 49 | internal init(myProperty: String, b: TestB) { 50 | self.myProperty = myProperty 51 | self.b = b 52 | } 53 | 54 | var myProperty: String 55 | let b: TestB 56 | let foo = ["foo1", "foo2", "foo3", "foo4", "foo5", "foo6", "foo7", "foo8", "foo9", "foo10"] 57 | let foo1 = ["foo1", "foo2", "foo3", "foo4", "foo5", "foo6", "foo7", "foo8", "foo9", "foo10"] 58 | let foo2 = ["foo1", "foo2", "foo3", "foo4", "foo5", "foo6", "foo7", "foo8", "foo9", "foo10"] 59 | let foo3 = ["foo1", "foo2", "foo3", "foo4", "foo5", "foo6", "foo7", "foo8", "foo9", "foo10"] 60 | } 61 | 62 | var exampleData = TestA(myProperty: "This is a string", b: TestB(number: 122, c: TestC(foo: 345))) 63 | -------------------------------------------------------------------------------- /Example/Example/ExampleApp.swift: -------------------------------------------------------------------------------- 1 | /** 2 | * Tree Dump Debugger 3 | * Copyright (c) Johan Thorell 2022 4 | * MIT license, see LICENSE file for details 5 | */ 6 | 7 | import SwiftUI 8 | 9 | @main 10 | struct ExampleApp: App { 11 | var body: some Scene { 12 | WindowGroup { 13 | ContentView() 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Example/Example/Preview Content/Preview Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 bangerang 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Tree Dump Debugger 2 | A visual developer tool for inspecting your iOS application data structures. 3 | 4 |

5 | drawing 6 | drawing 7 | drawing 8 |

9 | 10 | 11 | 12 | ## Features 13 | Inspect any data structure with only one line of code: 14 | 15 | ```swift 16 | TreeDumpDebugger.present(["foo": "bar", 122: [122, 45, 4]]) 17 | ``` 18 | 19 | Or from a SwiftUI view: 20 | 21 | ```swift 22 | Button("Press me") { 23 | showSwiftUIModal = true 24 | }.sheet(isPresented: $showSwiftUIModal) { 25 | TreeDumpDebugger.makeSwiftUIView(with: ["foo": "bar", 122: [122, 45, 4]]) 26 | } 27 | ``` 28 | 29 | You can modify any node in the tree, can be useful if you want different formatting or hide sensitive data: 30 | ```swift 31 | struct TestB { 32 | var number: Int 33 | } 34 | class TestA { 35 | init(myProperty: String, b: TestB) { 36 | self.myProperty = myProperty 37 | self.b = b 38 | } 39 | var myProperty: String 40 | let b: TestB 41 | } 42 | 43 | let data = TestA(myProperty: "This is a string", b: TestB(number: 122)) 44 | 45 | TreeDumpDebugger.present(data) { string in 46 | if let range = string.range(of: "This is a string") { 47 | return string.replacingCharacters(in: range, with: "Still a string but changed") 48 | } 49 | return string 50 | } 51 | 52 | TreeDumpDebugger.present(data) { string in 53 | return string.replacingOccurrences(of: "▿", with: "😎") 54 | } 55 | 56 | ``` 57 | 58 | ## How does it work? 59 | 60 | Tree Dump Debugger parses indented output into a tree structure. It uses Swift's built `dump` function by default. No private APIs are used. 61 | 62 | If you want to use another dumping tool it’s possible to do so by conforming to the `TreeDumpRepresentable` protocol. 63 | 64 | ```swift 65 | public protocol TreeDumpRepresentable { 66 | func makeLine(string: String, lineOutput: (String) -> Void) 67 | func dump(using tree: inout TreeDumpDebugger.Tree) 68 | } 69 | ``` 70 | 71 | So if we for instance would like to use [swift-custom-dump](https://github.com/pointfreeco/swift-custom-dump) which is another great dumping tool: 72 | ```swift 73 | import CustomDump 74 | 75 | struct CustomDump: TreeDumpRepresentable { 76 | let value: T 77 | var name: String? = nil 78 | var indent: Int = 0 79 | var maxDepth: Int = .max 80 | 81 | func makeLine(string: String, lineOutput: (String) -> Void) { 82 | let lines = string.components(separatedBy: .newlines) 83 | for line in lines { 84 | lineOutput(line) 85 | } 86 | } 87 | 88 | func dump(using tree: inout TreeDumpDebugger.Tree) { 89 | customDump(value, to: &tree, name: name, indent: indent, maxDepth: maxDepth) 90 | } 91 | 92 | } 93 | 94 | TreeDumpDebugger.present(CustomDump(value: data)) 95 | ``` 96 | 97 | ## Installation 98 | 99 | Simply drag and drop `TreeDumpDebugger.swift` into your project. Since this a debugging tool it’s probably a good idea to wrap the whole file in a `#if DEBUG`. 100 | 101 | ### Why no Swift Package? 102 | 103 | There is currently no support to conditionally embed a framework in `Package.swift` for a debug configuration, so a Swift Package would probably just do more harm than good. 104 | 105 | ## Requirements 106 | iOS 14 107 | 108 | ## Other ways of using it 109 | The repo also contains a LLDB script that can used to present the debugger view on the fly. 110 | ``` 111 | (lldb) tdump ["foo", "bar", 122, 3223] 112 | ``` 113 | 114 | drawing 115 | 116 | To use the script add this line to your `.lldbinit` 117 | ``` 118 | command script import 119 | ``` 120 | Or use [lowmad](https://github.com/bangerang/lowmad) 121 | ```bash 122 | $ lowmad install https://github.com/bangerang/tree-dump-debugger.git 123 | ``` 124 | -------------------------------------------------------------------------------- /Resources/example1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bangerang/tree-dump-debugger/659020afda2ec03fb86a779a89a11736a0fefb42/Resources/example1.png -------------------------------------------------------------------------------- /Resources/example2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bangerang/tree-dump-debugger/659020afda2ec03fb86a779a89a11736a0fefb42/Resources/example2.png -------------------------------------------------------------------------------- /Resources/video.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bangerang/tree-dump-debugger/659020afda2ec03fb86a779a89a11736a0fefb42/Resources/video.gif -------------------------------------------------------------------------------- /Resources/video2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bangerang/tree-dump-debugger/659020afda2ec03fb86a779a89a11736a0fefb42/Resources/video2.gif -------------------------------------------------------------------------------- /TreeDumpDebugger.swift: -------------------------------------------------------------------------------- 1 | /** 2 | * Tree Dump Debugger 3 | * Copyright (c) Johan Thorell 2022 4 | * MIT license, see LICENSE file for details 5 | */ 6 | 7 | import Foundation 8 | import UIKit 9 | import SwiftUI 10 | import Combine 11 | 12 | // MARK: API 13 | public struct TreeDumpDebugger { 14 | 15 | /// Presents a tree dump representation of `value` view on `window` 16 | /// 17 | /// - Parameters: 18 | /// - value: The value to output. 19 | /// - name: A label to use when writing the contents of `value`. When `nil` 20 | /// is passed, the label is omitted. The default is `nil`. 21 | /// - indent: The number of spaces to use as an indent for each line of the 22 | /// output. The default is `0`. 23 | /// - maxDepth: The maximum depth to descend when writing the contents of a 24 | /// value that has nested components. The default is `Int.max`. 25 | /// - maxItems: The maximum number of elements for which to write the full 26 | /// contents. The default is `Int.max`. 27 | /// - window: The window to present on. When `nil` is passed `keyWindow` is used. 28 | /// - visitingNode: Modify the given node. The default is `nil`. 29 | static public func present(_ value: T, 30 | name: String? = nil, 31 | indent: Int = 0, 32 | maxDepth: Int = .max, 33 | maxItems: Int = .max, 34 | in window: UIWindow? = nil, 35 | visitingNode: ((String) -> String)? = nil) { 36 | let keyWindow = UIWindow.resolveWindow(window) 37 | let dumpRepresentable = SwiftDump(value: value, name: name, indent: indent, maxDepth: maxDepth, maxItems: maxItems) 38 | present(dumpRepresentable, in: keyWindow, visitingNode: visitingNode) 39 | } 40 | 41 | /// Presents a tree dump representation of `dumpRepresentable` view on `window` 42 | /// 43 | /// - Parameters: 44 | /// - dumpRepresentable: /// An abstraction of something that can perform a dump of a `value` 45 | /// - window: The window to present on. When `nil` is passed `keyWindow` is used. 46 | /// - visitingNode: Modify the given node. The default is `nil`. 47 | static public func present(_ dumpRepresentable: TreeDumpRepresentable, 48 | in window: UIWindow? = nil, 49 | visitingNode: ((String) -> String)? = nil) { 50 | 51 | let keyWindow = UIWindow.resolveWindow(window) 52 | 53 | let hostingController = makeViewController(with: dumpRepresentable, visitingNode: visitingNode) 54 | 55 | var topViewController = keyWindow.rootViewController 56 | 57 | while let newTopViewController = topViewController?.presentedViewController { 58 | topViewController = newTopViewController 59 | } 60 | 61 | topViewController?.present(hostingController, animated: true) 62 | } 63 | 64 | /// Wraps a tree dump view with `value` inside a view controller 65 | /// 66 | /// - Parameters: 67 | /// - value: The value to output. 68 | /// - name: A label to use when writing the contents of `value`. When `nil` 69 | /// is passed, the label is omitted. The default is `nil`. 70 | /// - indent: The number of spaces to use as an indent for each line of the 71 | /// output. The default is `0`. 72 | /// - maxDepth: The maximum depth to descend when writing the contents of a 73 | /// value that has nested components. The default is `Int.max`. 74 | /// - maxItems: The maximum number of elements for which to write the full 75 | /// contents. The default is `Int.max`. 76 | /// - visitingNode: Modify the given node. The default is `nil`. 77 | static func makeViewController(with value: T, 78 | name: String? = nil, 79 | indent: Int = 0, 80 | maxDepth: Int = .max, 81 | maxItems: Int = .max, 82 | visitingNode: ((String) -> String)? = nil) -> UIHostingController { 83 | return UIHostingController(rootView: makeSwiftUIView(with: value, visitingNode: visitingNode)) 84 | } 85 | 86 | /// Wraps a tree dump view with `dumpRepresentable` inside a view controller 87 | /// 88 | /// - Parameters: 89 | /// - dumpRepresentable: /// An abstraction of something that can perform a dump of a `value` 90 | /// - visitingNode: Modify the given node. The default is `nil`. 91 | static func makeViewController(with dumpRepresentable: TreeDumpRepresentable, 92 | visitingNode: ((String) -> String)? = nil) -> UIHostingController { 93 | return UIHostingController(rootView: makeSwiftUIView(with: dumpRepresentable, visitingNode: visitingNode)) 94 | } 95 | 96 | 97 | /// Makes a SwiftUI tree dump view with `value` 98 | /// 99 | /// - Parameters: 100 | /// - name: A label to use when writing the contents of `value`. When `nil` 101 | /// is passed, the label is omitted. The default is `nil`. 102 | /// - indent: The number of spaces to use as an indent for each line of the 103 | /// output. The default is `0`. 104 | /// - maxDepth: The maximum depth to descend when writing the contents of a 105 | /// value that has nested components. The default is `Int.max`. 106 | /// - maxItems: The maximum number of elements for which to write the full 107 | /// contents. The default is `Int.max`. 108 | /// - visitingNode: Modify the given node. The default is `nil`. 109 | static func makeSwiftUIView(with value: T, 110 | name: String? = nil, 111 | indent: Int = 0, 112 | maxDepth: Int = .max, 113 | maxItems: Int = .max, 114 | visitingNode: ((String) -> String)? = nil) -> DumperTreeView { 115 | return makeSwiftUIView(with: SwiftDump(value: value), visitingNode: visitingNode) 116 | } 117 | 118 | /// Makes a tree dump view with `dumpRepresentable` 119 | /// 120 | /// - Parameters: 121 | /// - dumpRepresentable: /// An abstraction of something that can perform a dump of a `value` 122 | /// - visitingNode: Modify the given node. The default is `nil`. 123 | static func makeSwiftUIView(with dumpRepresentable: TreeDumpRepresentable, 124 | visitingNode: ((String) -> String)? = nil) -> DumperTreeView { 125 | let tree = Tree(dumpRepresentable: dumpRepresentable, visitingNode: visitingNode) 126 | let model = Model(tree: tree) 127 | return DumperTreeView(model: model) 128 | } 129 | } 130 | 131 | /// An abstraction of something that can perform a dump of a `value` 132 | public protocol TreeDumpRepresentable { 133 | func makeLine(string: String, lineOutput: (String) -> Void) 134 | func dump(using tree: inout TreeDumpDebugger.Tree) 135 | } 136 | 137 | // MARK: Implementation 138 | extension TreeDumpDebugger { 139 | 140 | private struct SearchBar: View { 141 | 142 | let searchBarColor = (light: Color(red: 229.0/255.0, green: 229.0/255.0, blue: 230.0/255.0), 143 | dark: Color(red: 44.0/255.0, green: 44.0/255.0, blue: 46.0/255.0)) 144 | 145 | @Binding var searchText: String 146 | @Environment(\.colorScheme) var colorScheme 147 | 148 | var body: some View { 149 | ZStack { 150 | Rectangle() 151 | .foregroundColor(colorScheme == .dark ? searchBarColor.dark : searchBarColor.light) 152 | HStack { 153 | Image(systemName: "magnifyingglass") 154 | .foregroundColor(.gray) 155 | TextField("Search ..", text: $searchText) 156 | .foregroundColor(colorScheme == .dark ? .white : .black) 157 | } 158 | .padding(.leading, 13) 159 | } 160 | .frame(height: 40) 161 | .cornerRadius(13) 162 | .padding() 163 | } 164 | } 165 | 166 | struct DumperTreeView: View { 167 | @ObservedObject fileprivate var model: Model 168 | @Environment(\.colorScheme) var colorScheme 169 | 170 | let backgroundColor = (light: Color(red: 242.0/255.0, green: 242.0/255.0, blue: 247.0/255.0), 171 | dark: Color(red: 28.0/255.0, green: 28.0/255.0, blue: 31.0/255.0)) 172 | 173 | var body: some View { 174 | NavigationView { 175 | VStack { 176 | if model.loading { 177 | ProgressView() 178 | } else { 179 | SearchBar(searchText: $model.searchText) 180 | List(model.nodes, children: \.children) { node in 181 | Text(node.value) 182 | } 183 | } 184 | } 185 | .background(colorScheme == .light ? backgroundColor.light : backgroundColor.dark) 186 | .navigationTitle("Tree dump debugger") 187 | .navigationBarTitleDisplayMode(.inline) 188 | .toolbar { 189 | Button("Reload") { 190 | model.didPressReload() 191 | } 192 | } 193 | } 194 | } 195 | } 196 | } 197 | 198 | private extension TreeDumpDebugger { 199 | class Model: ObservableObject { 200 | @Published var searchText: String = "" 201 | @Published private(set) var loading = true 202 | @Published private(set) var nodes: [TreeDumpDebugger.Node] = [] 203 | private var tree: Tree 204 | private var cancellable: Cancellable? 205 | private let dispatchQueue = DispatchQueue(label: "TreeDumpDebugger", qos: .userInitiated) 206 | 207 | public init(tree: Tree) { 208 | self.tree = tree 209 | cancellable = $searchText.debounce(for: .milliseconds(300), scheduler: RunLoop.main) 210 | .sink { [weak self] searchText in 211 | self?.handleSearch(searchText) 212 | } 213 | dump() 214 | } 215 | 216 | public func didPressReload() { 217 | searchText = "" 218 | dump() 219 | } 220 | 221 | private func dump() { 222 | loading = true 223 | dispatchQueue.sync { 224 | self.tree.dump() 225 | DispatchQueue.main.async { [weak self] in 226 | self?.loading = false 227 | } 228 | } 229 | } 230 | 231 | private func resetTree() { 232 | nodes = tree.rootNodes 233 | } 234 | 235 | private func handleSearch(_ string: String) { 236 | if searchText.isEmpty { 237 | resetTree() 238 | } else { 239 | dispatchQueue.sync { [rootNodes = tree.rootNodes, searchText] in 240 | let map = rootNodes.map { 241 | $0.search(for: searchText) 242 | } 243 | let searchResult = map.flatMap { $0 } 244 | DispatchQueue.main.async { [weak self] in 245 | self?.nodes = searchResult 246 | } 247 | } 248 | } 249 | } 250 | } 251 | } 252 | 253 | extension TreeDumpDebugger { 254 | class Node: Identifiable { 255 | let value: T 256 | var id: String { 257 | return String(ObjectIdentifier(self).hashValue) 258 | } 259 | var depth: Int = 0 260 | var children: [Node]? 261 | weak var parent: Node? 262 | 263 | init(value: T) { 264 | self.value = value 265 | } 266 | 267 | func addChild(_ child: Node) { 268 | if children == nil { 269 | children = [] 270 | } 271 | children?.append(child) 272 | } 273 | } 274 | } 275 | 276 | extension TreeDumpDebugger.Node where T == String { 277 | func search(for string: String) -> [TreeDumpDebugger.Node] { 278 | var result: [TreeDumpDebugger.Node] = [] 279 | if value.lowercased().contains(string.lowercased()) { 280 | result.append(self) 281 | } 282 | if let children = children { 283 | for child in children { 284 | result.append(contentsOf: child.search(for: string)) 285 | } 286 | } 287 | 288 | return result 289 | } 290 | } 291 | 292 | extension TreeDumpDebugger { 293 | public struct Tree: TextOutputStream { 294 | private var indentDict: [String.Index: [Node]] = [:] 295 | private var prev: Node? 296 | private(set) var rootNodes: [Node] = [] 297 | private let dumpRepresentable: TreeDumpRepresentable 298 | private var visitingNode: ((String) -> String)? 299 | 300 | public init(dumpRepresentable: TreeDumpRepresentable, visitingNode: ((String) -> String)? = nil) { 301 | self.visitingNode = visitingNode 302 | self.dumpRepresentable = dumpRepresentable 303 | } 304 | 305 | public mutating func dump() { 306 | indentDict.removeAll() 307 | rootNodes.removeAll() 308 | prev = nil 309 | dumpRepresentable.dump(using: &self) 310 | } 311 | 312 | public mutating func write(_ string: String) { 313 | dumpRepresentable.makeLine(string: string) { line in 314 | handleLine(line) 315 | } 316 | } 317 | 318 | private mutating func handleLine(_ line: String) { 319 | 320 | let node: Node = { 321 | if let visitingNode = visitingNode { 322 | let newValue = visitingNode(line) 323 | return Node(value: newValue) 324 | } else { 325 | return Node(value: line) 326 | } 327 | }() 328 | 329 | if rootNodes.isEmpty { 330 | rootNodes.append(node) 331 | } 332 | 333 | guard let nodeIndentLevel = line.firstIndex(where: { !$0.isWhitespace }) else { 334 | return 335 | } 336 | 337 | if let prev = prev { 338 | let prevIndentLevel = prev.value.firstIndex(where: { !$0.isWhitespace })! 339 | if prevIndentLevel == nodeIndentLevel { 340 | node.depth = prev.depth 341 | node.parent = prev.parent 342 | prev.parent?.addChild(node) 343 | } else if prevIndentLevel < nodeIndentLevel { 344 | node.depth = prev.depth + 1 345 | node.parent = prev 346 | prev.addChild(node) 347 | } else { 348 | if let sibling = indentDict[nodeIndentLevel]?.popLast() { 349 | node.depth = sibling.depth 350 | if sibling.parent == nil { 351 | rootNodes.append(node) 352 | } else { 353 | node.parent = sibling.parent 354 | sibling.parent?.addChild(node) 355 | } 356 | } 357 | } 358 | } 359 | 360 | indentDict[nodeIndentLevel, default: []].append(node) 361 | prev = node 362 | } 363 | } 364 | } 365 | 366 | extension TreeDumpDebugger { 367 | public class SwiftDump: TreeDumpRepresentable { 368 | let value: T 369 | let name: String? 370 | let indent: Int 371 | let maxDepth: Int 372 | let maxItems: Int 373 | 374 | public init(value: T, name: String? = nil, indent: Int = 0, maxDepth: Int = .max, maxItems: Int = .max) { 375 | self.value = value 376 | self.name = name 377 | self.indent = indent 378 | self.maxDepth = maxDepth 379 | self.maxItems = maxItems 380 | } 381 | 382 | private var line = "" 383 | public func makeLine(string: String, lineOutput: (String) -> Void) { 384 | line += string 385 | 386 | if let last = line.last, last.isNewline { 387 | line.removeLast() // Remove new line 388 | lineOutput(line) 389 | line = "" 390 | } 391 | } 392 | 393 | public func dump(using tree: inout TreeDumpDebugger.Tree) { 394 | Swift.dump(value, to: &tree, name: name, indent: indent, maxDepth: maxDepth, maxItems: maxItems) 395 | } 396 | } 397 | } 398 | 399 | fileprivate extension UIWindow { 400 | private static var keyWindow: UIWindow? { 401 | return UIApplication.shared.connectedScenes 402 | .filter { $0.activationState == .foregroundActive } 403 | .first(where: { $0 is UIWindowScene }) 404 | .flatMap({ $0 as? UIWindowScene })?.windows 405 | .first(where: \.isKeyWindow) 406 | } 407 | 408 | static func resolveWindow(_ window: UIWindow?) -> UIWindow { 409 | let keyWindow = window ?? keyWindow 410 | guard let keyWindow = keyWindow else { 411 | fatalError("Could not resolve key window") 412 | } 413 | return keyWindow 414 | } 415 | } 416 | -------------------------------------------------------------------------------- /tdump.py: -------------------------------------------------------------------------------- 1 | import lldb 2 | import os 3 | import shlex 4 | import optparse 5 | 6 | @lldb.command("tdump") 7 | def handle_tdump_command(debugger, expression, ctx, result, internal_dict): 8 | 9 | res = lldb.SBCommandReturnObject() 10 | interpreter = debugger.GetCommandInterpreter() 11 | 12 | commands = [ 13 | 'e -l swift -- import {}'.format(ctx.target), 14 | 'e -l swift -- import UIKit', 15 | 'e -l swift -- TreeDumpDebugger.present({})'.format(expression), 16 | 'e -l swift -- CATransaction.flush()' 17 | ] 18 | 19 | for command in commands: 20 | interpreter.HandleCommand(command, res) 21 | if res.GetError(): 22 | result.SetError(res.GetError()) 23 | return 24 | 25 | target = debugger.GetSelectedTarget() 26 | process = target.GetProcess() 27 | result.SetStatus(lldb.eReturnStatusSuccessContinuingNoResult) 28 | debugger.SetAsync(True) 29 | process.Continue() 30 | 31 | 32 | 33 | --------------------------------------------------------------------------------