Xcode offers a wealth of great tools for debugging. Sometimes though, we'd like to be able to debug or evaluate the inner-workings of our app without needing to be connected to Xcode's debugger.
Today we'll check out TinyConsole by Devran Γnal, a library that lets us easily display our log messages directly inside our app. Let's take a look.
We'll install TinyConsole into our app, then slightly modify some code in our AppDelegate
to set it up.
Instead of assigning our root view controller like this:
self.window.rootViewController = SpaceshipsViewController()
We'll wrap our root view controller in a TinyConsoleController
:
self.window = TinyConsoleController(
rootViewController: SpaceshipsViewController()
)
That's it. Now all we need to do is add some log messages throughout our code. We can do this with calls like:
TinyConsole.print("spacehip id: \(spaceship.id)")
Now, we can launch our app and try it out. When running on a device, we can simply shake the device to show/hide the console view.
(Pro Tip: Press ββZ to simulate a shake in the iOS Simulator).
Neat! TinyConsole doesn't stop there though, we can also use colors:
TinyConsole.print("Crew Member Saved!", color: UIColor.green)
and add Markers:
TinyConsole.addMarker()
Finally, there's a few more gestures available (in addition to shaking to hide/show).
We can swipe to add a Marker, tap with 2 fingers to log something manually, or tap with 3 fingers to show an Action Sheet that allows us to send our log messages as an email.
Learn more about TinyConsole at git.io/tinyconsole