a debugging library written in Swift

Debugging is a process that helps developers track down and fix errors in software. A debugging library written in Swift will help developers create more efficient, reliable apps with the ability to debug code on the fly.

The xcode print view hierarchy is a debugging library written in Swift that can be used to show the view hierarchy.

Inspector is a Swift-based debugging library.

Header Demo GIF

Why would you want to utilize it?

Enhance your development experience

  • Use key commands and add your own custom commands to the primary Inspector interface when using the Simulator.app (and also on iPad).
  • Create layer views based on whatever criterion you choose to help you see the status of your application: a class, a property, or anything else.
  • Instead of utilizing Xcode’s built-in view hierarchy inspector, you may use this one.
  • Without Xcode, inspect the view hierarchy.
  • Changes are tested and perspectives are corrected in real time.

With a reverse Zeplin, you can improve QA and Designer input.

  • Without Xcode, inspect the view hierarchy.
  • Changes are tested and perspectives are corrected in real time.
  • Validate particular state behaviors with ease.
  • A better knowledge of component inner workings
  • Give developers more precise input.

Requirements

  • iOS 11.0 and above
  • Xcode 11 and up
  • Swift 5.3 and up

Installation

Swift Package Manager is a program that allows you to manage your

The Swift Package Manager, which is built into the Swift compiler, is a tool for automating the distribution of Swift code. Although it is still in early stages of development, Inspector supports its usage on supported systems.

Adding Inspector as a dependent is as simple as adding it to your Package’s dependencies field after you’ve built up your Swift package. swift.

/ Add the following to the Package.swift dependencies: [.package(url: “https://github.com/ipedro/Inspector.git”,.upToNextMajor(from: “1.0.0”)) ] [.package(url: “https://github.com/ipedro/Inspector.git”,.upToNextMajor(from: “1.0.0”))


Setup

After a successful installation, you must add InspectorHostable protocol compliance to SceneDelegate. Swift or AppDelegate are two options. Speedy takes up the role of Inspector host.

SceneDelegate.swift

Example of a Scene Delegate #if DEBUG import Inspector extension import UIKit InspectorHostable is the scene delegate. inspectorViewHierarchyLayers: [Inspector.ViewHierarchyLayer]? var inspectorViewHierarchyLayers: [Inspector.ViewHierarchyLayer]? inspectorViewHierarchyColorScheme: Inspector.ViewHierarchyColorScheme? var inspectorViewHierarchyColorScheme: Inspector.ViewHierarchyColorScheme? nil nil nil nil nil nil nil inspectorCommandGroups: [Inspector.CommandsGroup]? var inspectorCommandGroups: [Inspector.CommandsGroup]? inspectorElementLibraries: [InspectorElementLibraryProtocol]? var inspectorElementLibraries: [InspectorElementLibraryProtocol]? nil nil nil nil nil nil nil nil class #endif UIResponder, UIWindowSceneDelegate are examples of SceneDelegates. UIWindow as a var window? func scene(_ scene: UIScene, willConnect); func scene(_ scene: UIScene; func scene(_ scene: U UISceneSession, connectionOptions: UIScene.ConnectionOptions) to session #if DEBUG / When connecting to a session Inspector, make your class the host. # host = self endif guard set = (UIWindowScene as? UIWindowScene) else return ……

AppDelegate.swift

Example of an App Delegate #if DEBUG import Inspector extension import UIKit InspectorHostable is the appDelegate. inspectorViewHierarchyLayers: [Inspector.ViewHierarchyLayer]? var inspectorViewHierarchyLayers: [Inspector.ViewHierarchyLayer]? var inspectorViewHierarchy = null Inspector.ViewHierarchyColorScheme? ColorScheme: Inspector.ViewHierarchyColorScheme? inspectorCommandGroups: [Inspector.CommandsGroup]? var inspectorCommandGroups: [Inspector.CommandsGroup]? inspectorElementLibraries: [InspectorElementLibraryProtocol]? var inspectorElementLibraries: [InspectorElementLibraryProtocol]? nil nil nil nil nil nil nil nil final class #endif UIResponder, UIApplicationDelegate are examples of AppDelegates. var window: UIWindow? func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any], didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any], didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOption -> Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> ……

Activate Key Commands (Recommended)

To allow Inspector key commands, extend the root view controller class.

/ Add to your view controller’s root. var keyCommands: [UIKeyCommand]? #if DEBUG override var keyCommands: [UIKeyCommand]? inspectorManager?.keyCommands = return #endif

Framework files should be removed from release builds (Optional)

In your app, you should aim for:

  • As the last step, add a New Run Script Phase.
  • Then, to delete any Inspector-related files from your release builds, paste the script below.

# Execute a script to remove Inspector and all of its dependencies from release builds. find $TARGET BUILD DIR/$FULL PRODUCT NAME -name “Inspector*” | grep. | xargs rm -rf find $TARGET BUILD DIR/$FULL PRODUCT NAME -name “UIKeyCommandTableView*” | grep. | xargs rm -rf find $TARGET BUILD DIR/$FU | grep. | xargs rm -rf find $TARGET BUILD DIR/$FULL PRODUCT NAME -name “UIKitOptions*” | grep. | xargs rm -rf find $TARGET BUILD DIR/$FULL PRODUCT NAME -name “UIKitOptions*”


Introducing the Inspector

By using the presentInspector(animated:_:) function from any view controller or window instance, the inspector may be shown. And here are some ideas on how you might do it in a variety of innovative ways.

Using the Key Commands that are already installed (Available on Simulator and iPads)

a-debugging-library-written-in-Swift

Using the Simulator.app or a real iPad after activating Key Commands functionality, you can:

  • Inspector is activated by pressing Ctrl + Shift + 0.

  • By pressing Ctrl + Shift + 1-8, you may toggle between displaying and concealing view layers.

  • By pressing Ctrl + Shift + 9, you may see or hide all layers.

  • You may use any key command to start custom commands.

Making use of the built-in BarButtonItem

Every UIViewController instance has the var inspectorBarButtonItem: UIBarButtonItem get available as a convenience. It takes care of the presentation for you, and all you have to do is add it to your tool bar (or navigation) like this:

/ Add an override function to any view controller. if DEBUG navigationItem.rightBarButtonItem = self.inspectorBarButtonItem #endif if DEBUG navigationItem.rightBarButtonItem = self.inspectorBarButtonItem #endif if DEBUG navigationItem.rightBarButtonItem = self.inspectorBarButtonItem #endif if DEBUG navigationItem.rightBarButtonItem = self.inspectorBarButtonItem

The use of motion gestures

You may also use a motion to display Inspector, such as shaking the smartphone. This eliminates the requirement for a user interface. Subclassing (or extending) UIWindow using the following code is a convenient method to accomplish it:

Declare it inside a subclass or UIWindow extension. #override method motionBegan(_ motion: UIEvent.EventSubtype, with event: UIEvent?) if DEBUG is enabled. super.motionBeginnnnnnnnnnnnnnnn (motion, with: event) .motion == guard motion Otherwise, sway. presentInspector(animated: true) return #endif

Customizing the user interface

You may use presentInspector(animated:_:) yourself after building a custom interface in your program, such as a floating button or any other control of your choice.

When adding event targets to a UIControl, you may use the convenient selector UIViewController.inspectorManagerPresentation().

If your view derives from UIControl, add myControl to any view controller. super.viewDidLoad() #if DEBUG myControl override func viewDidLoad() #if DEBUG myControl #endif addTarget(self, action: #selector(UIViewController.inspectorManagerPresentation), for: UIControl.Event) addTarget(self, action: #selector(UIViewController.inspectorManagerPresentation), for: UIControl.Event) addTarget(self, action: #selector(


Customization

Through the Protocol for InspectorHostable, Inspector enables you to modify and add new behavior on views unique to your codebase.

InspectorHostable Protocol


inspectorViewHierarchyLayers = [Inspector.ViewHierarchyLayer]? var inspectorViewHierarchyLayers = [Inspector.ViewHierarchyLayer]? obtain

Toggles for ViewHierarchyLayer may be found in the Highlight views area of the Inspector interface, and they can also be activated with Ctrl + Shift + 1 – 8. You have the option of using one of the defaults or creating your own.

Layers in the Default View Hierarchy:

  • activityIndicators: Displays views of activity indicators.
  • buttons: Displays a list of buttons.
  • collectionViews: Displays a list of collection views.
  • containerViews: This property displays all container views.
  • controls: Displays all of the controls.
  • images: Displays a list of all picture views.
  • All map views are shown in this view.
  • Views of pickers: Displays all picker views.
  • All progress indicator views are shown in progressIndicators.
  • scrollViews: Returns a list of all scroll views.
  • All segmented controls are shown in segmentedControls.
  • spacerViews: Returns a list of all spacer views.
  • stackViews: Returns a list of all stack views.
  • tableViewCells: Displays the contents of all table view cells.
  • collectionViewReusableVies: Displays all resusable views in the collection.
  • collectionViewCells: This property displays all of the collection view cells.
  • staticTexts: Returns a list of all static texts.
  • All switches are shown.
  • tables: Displays a list of all table views.
  • textFields: Returns a list of all text fields.
  • textViews: Returns a list of all text views.
  • textInputs: Displays a list of all text inputs.
  • webViews: Displays a list of all web views.

InspectorViewHierarchyLayers, for example: [Inspector.ViewHierarchyLayer]? [.controls,.buttons,.staticTexts +.images,.layer( name: “Without accessibility identifiers”, filter: element in guard let accessibilityIdentifier = element.accessibilityIdentifier?.trimmingCharacters(in:.whitespacesAndNewlines) else return true return accessibilityIdentifier.isEmpty) else return true return accessibilityIdentifier.isEmpty) else return true return accessibilityIdentifier.isEmpty) else return


InspectorViewHierarchyColorScheme: var inspectorViewHierarchyColorScheme: var inspectorViewHierarchyColorScheme ViewHierarchyColorScheme? obtain

Instead of (or in addition to) the default color scheme, return your own color scheme for the hierarchy label colors.

Inspector is an example of a var inspectorViewHierarchyColorScheme. Return.systemPink default: / fallback to default color scheme if ViewHierarchyColorScheme?.colorScheme view in switch view case is MyView: return Inspector.ViewHierarchyColorScheme.default.color(for: view) return Inspector.ViewHierarchyColorScheme.default.color(for: view) return Inspector.ViewHierarchyColorScheme.default.color(for


inspectorCommandGroups: [Inspector.CommandGroup]? var inspectorCommandGroups: [Inspector.CommandGroup]? obtain

You may have as many groups as you want, with as many commands as you want. Command groups show as sections on the main Inspector UI and can have key command shortcuts linked with them.

InspectorCommandGroups is an example of a var inspectorCommandGroups: [Inspector.CommandGroup]? guardian if window = window, then return [] ] ] ] ] ] ] ] ] ] [.group( title: “My custom commands”, commands: [.command( title: “Reset”, icon:.exampleCommandIcon, key:.exampleCommandIcon, key:.exampleCommandIcon, key:.exampleCommandIcon, key:.exampleCommandIcon, key closure:.control(.shift(.key(“r”)), command:.control(.shift(.key(“r”)) / On a Storyboard application, creates a new initial view controller. let vc = storyboard.instantiateInitialViewController() / assign new instance as the root view controller window. let storyboard = UIStoryboard(name: “Main”, bundle: nil) rootViewController = vc / restart inspector Insopector.restart() ) ] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ] ]


inspectorElementLibraries: [InspectorElementLibraryProtocol] var inspectorElementLibraries: [InspectorElementLibraryProtocol] var inspectorElementLibraries: obtain

Element Libraries are InspectorElementLibraryProtocol-compliant entities that are individually associated with a certain type. Enumerations are a good way to go.

InspectorElementLibrariesProtocol: [InspectorElementLibraryProtocol] is an example var inspectorElementLibraries. allCases.ExampleElementLibrary / Inspector enum import UIKit / Element Library Example InspectorElementLibraryProtocol, CaseIterable are examples of element libraries. in this instance targetClass my myClass var targetClass var targetClass = targetClass var targetClass var target func viewModel(for referenceView: UIView) -> InspectorElementViewModelProtocol? switch self case.myClass: return MyView.self func viewModel(for referenceView: UIView) -> InspectorElementViewModelProtocol? return MyClassInspectableViewModel(view: referenceView) func icon(for referenceView: UIView) -> UIImage? switch self case.myClass: return MyClassInspectableViewModel(view: referenceView) func icon(for referenceView: UIView) -> UIImage? switch self case.myClass: return UIImage(named: “MyClassIcon”) / optional UIImage(named: “MyClassIcon”) / Inspector final class import UIKit import Element ViewModel let myObject: MyView init? MyClassInspectableViewModel: InspectorElementViewModelProtocol var title: String = “My View” guard (view: UIView) allow myObject to be seen as? Otherwise, my point of view return nil self.myObject = myObject nil nil nil nil nil nil nil nil nil nil enum String and CaseIterable are two properties. in this instance case backgroundColor = “Background Color” case cornerRadius = “Round Corners” [InspectorElementViewModelProperty] is a var property. Properties.allCases.map is a map of all the cases in a property. return.toggleButton( title: property.rawValue, isOn: self.myObject.roundCorners ) in switch property case.cornerRadius [weak self] in a circle let self = self else return self.myObject.round corners in guard case.background.corners = roundCorners color:.color; return.color; return.color; return. Picker (property.raw) is a picker with the title property.raw. self.myObject.backgroundColor (value, color) new [weak self] let self = self otherwise return self.myObject.backgroundColor = new BackgroundColor in guard bgColor bgColor bgColor bgColor bgColor bgColor bg


GitHub

https://github.com/ipedro/Inspector

The debug ios app without xcode is a debugging library written in Swift that can be used to debug iOS apps.

Related Tags

  • swiftui debug view hierarchy
  • ui debugger xcode
  • xcode debugging tips
  • view hierarchy ios
  • xcode debug view hierarchy