CheatCodes is a drop in tool to enable debugging functionality in the simulator by using UIKeyCommand
. It also provides tools to build your own custom commands with formatted output.
The following commands are available by default:
Available Cheat Codes:
======================
⌘ + ⇧ + ^ + ↓: Trigger restorable state preservation
⇧ + ^ + d: Print documents directory path
⇧ + ^ + e: Re-enable user interaction
⇧ + ^ + h: Print the list of available commands
⇧ + ^ + i: Print general device info
⇧ + ^ + l: Print autolayout backtrace
⇧ + ^ + o: Print the current trait collection (for the main window)
⇧ + ^ + t: Cycle tintAdjustmentMode
⇧ + ^ + u: Print user defaults
While this pod is configured to make itself essentially empty for "Release" builds, it's possible that your project may use an alternate build configuration name for app store releases. You should take care to ensure that this pod is not available in any publicly available builds.
In Xcode 8, add to your project under Active Compilation Conditions
(SWIFT_ACTIVE_COMPILATION_CONDITIONS):
Active Compilation Conditions > Debug > CHEATS_ENABLED
class AppDelegate {
#if CHEATS_ENABLED
override var keyCommands: [UIKeyCommand]? {
return UIKeyCommand.cheatCodes
}
#endif
}
#if CHEATS_ENABLED
extension AppDelegate {
func configureCustomCheats() {
[
CheatCodeCommand(input: "g", action: #selector(logInUser), discoverabilityTitle: "Log in a default user account"),
CheatCodeCommand(input: "f", modifierFlags: [.command, .alternate], action: #selector(resetFirstRunScreens), discoverabilityTitle: "Reset all first run screens"),
].forEach { UIKeyCommand.addCheatCode($0) }
}
func logInUser() {
print("Log in a user")
}
func resetFirstRunScreens() {
print("First run screens reset!")
}
}
#endif
While you will not see the overlay that hints at which items are available, these do in fact work on the iPhone simulators (make sure Hardware > Keyboard > Connect Hardware Keyboard
is enabled)
To run the example project, clone the repo, and run pod install
from the Example directory first.
- Swift 3.0+
- iOS 8+
CheatCodes is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "CheatCodes"
Dave Lyon, [email protected]
CheatCodes is available under the MIT license. See the LICENSE file for more info.