♂️ Inspector
Inspector is a debugging library written in Swift.
Why use it?
Improve development experience
- Add your own custom commands to the main
Inspector
interface and make use of key commands while using the Simulator.app (and also on iPad). - Create layer views by any criteria you choose to help you visualize application state: class, a property, anything.
- Inspect view hierarchy faster then using Xcode's built-in one, or
- Inspect view hierarchy without Xcode.
- Test changes and fix views live.
Improve QA and Designer feedback with a reverse Zeplin
- Inspect view hierarchy without Xcode.
- Test changes and fix views live.
- Easily validate specific state behaviors.
- Better understanding of the inner-workings of components
- Give more accurate feedback for developers.
Requirements
- iOS 11.0+
- Xcode 11+
- Swift 5.3+
Installation
Swift Package Manager
The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the swift compiler. It is in early development, but Inspector does support its use on supported platforms.
Once you have your Swift package set up, adding Inspector
as a dependency is as easy as adding it to the dependencies value of your Package.swift
.
Setup
After a successful installation, you need to add conformance to the InspectorHostable
protocol in SceneDelegate.swift
or AppDelegate.swift
assign itself as Inspector
host.
SceneDelegate.swift
AppDelegate.swift
Enable Key Commands (Recommended)
Extend the root view controller class to enable Inspector
key commands.
Remove framework files from release builds (Optional)
In your app target:
- Add a
New Run Script Phase
as the last phase. - Then paste the script below to remove all
Inspector
related files from your release builds.
Presenting the Inspector
The inspector can be presented from any view controller or window instance by calling the presentInspector(animated:_:)
method. And that you can achieve in all sorts of creative ways, heres some suggestions.
Using built-in Key Commands (Available on Simulator and iPads)
After enabling Key Commands support, using the Simulator.app or a real iPad, you can:
-
Invoke
Inspector
by pressing Ctrl + Shift + 0. -
Toggle between showing/hiding view layers by pressing Ctrl + Shift + 1-8.
-
Showing/hide all layers by pressing Ctrl + Shift + 9.
-
Trigger custom commands with any key command you want.
Using built-in BarButtonItem
As a convenience, there is the var inspectorBarButtonItem: UIBarButtonItem { get }
availabe on every UIViewController
instance. It handles the presentation for you, and just needs to be set as a tool bar (or navigation) items, like this:
With motion gestures
You can also present Inspector
using a gesture, like shaking the device. That way no UI needs to be introduced. One convienient way to do it is subclassing (or extending) UIWindow
with the following code:
Adding custom UI
After creating a custom interface on your app, such as a floating button, or any other control of your choosing, you can call presentInspector(animated:_:)
yourself.
If you are using a UIControl
you can use the convenenice selector UIViewController.inspectorManagerPresentation()
when adding event targets.
Customization
Inspector
allows you to customize and introduce new behavior on views specific to your codebase, through the InspectorHostable
Protocol.
InspectorHostable Protocol
var window: UIWindow? { get }
var inspectorViewHierarchyLayers: [Inspector.ViewHierarchyLayer]? { get }
var inspectorViewHierarchyColorScheme: Inspector.ViewHierarchyColorScheme? { get }
var inspectorCommandGroups: [Inspector.CommandGroup]? { get }
var inspectorElementLibraries: [InspectorElementLibraryProtocol] { get }
var inspectorViewHierarchyLayers: [Inspector.ViewHierarchyLayer]? { get }
ViewHierarchyLayer
are toggleable and shown in the Highlight views
section on the Inspector interface, and also can be triggered with Ctrl + Shift + 1 - 8. You can use one of the default ones or create your own.
Default View Hierarchy Layers:
activityIndicators
: Shows activity indicator views.buttons
: Shows buttons.collectionViews
: Shows collection views.containerViews
: Shows all container views.controls
: Shows all controls.images
: Shows all image views.maps
: Shows all map views.pickers
: Shows all picker views.progressIndicators
: Shows all progress indicator views.scrollViews
: Shows all scroll views.segmentedControls
: Shows all segmented controls.spacerViews
: Shows all spacer views.stackViews
: Shows all stack views.tableViewCells
: Shows all table view cells.collectionViewReusableVies
: Shows all collection resusable views.collectionViewCells
: Shows all collection view cells.staticTexts
: Shows all static texts.switches
: Shows all switches.tables
: Shows all table views.textFields
: Shows all text fields.textViews
: Shows all text views.textInputs
: Shows all text inputs.webViews
: Shows all web views.
var inspectorViewHierarchyColorScheme: Inspector.ViewHierarchyColorScheme? { get }
Return your own color scheme for the hierarchy label colors, instead of (or to extend) the default color scheme.
var inspectorCommandGroups: [Inspector.CommandGroup]? { get }
Command groups appear as sections on the main Inspector
UI and can have key command shortcuts associated with them, you can have as many groups, with as many commands as you want.
var inspectorElementLibraries: [InspectorElementLibraryProtocol] { get }
Element Libraries are entities that conform to InspectorElementLibraryProtocol
and are each tied to a unique type. Pro-tip: Use enumerations.