CheatCodes 0.2.1

CheatCodes 0.2.1

测试已测试
语言语言 SwiftSwift
许可协议 MIT
发布日期上次发布日期2016年11月
SPM支持 SPM

Dave Lyon 维护。



CheatCodes

关于

CheatCodes 是一个可以用于在模拟器中启用调试功能并使用 UIKeyCommand 的即插式工具。它还提供了构建自己的自定义命令的工具,并提供格式化的输出。

以下命令为默认可用:

Available Cheat Codes:
======================
 ⌘ + ⇧ + ^ + ↓: Trigger restorable state preservation
     ⇧ + ^ + d: Print documents directory path
     ⇧ + ^ + e: Re-enable user interaction
     ⌘ + ⌥ + f: Reset all first run screens
     ⇧ + ^ + g: Log in a default user account
     ⇧ + ^ + 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

警告

虽然此库配置为在“发布”构建中将本身完全留空,但您的项目可能使用不同的构建配置名称为应用商店发布。您应确保此库不在任何公开可用的构建中可用。

使用

标识符

在 Xcode 8 中,将以下内容添加到项目的 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

注意

虽然您将看不到重叠提示,表示可以使用的项目,但这些实际上在 iPhone 模拟器上确实有效(请确保已启用 Hardware > Keyboard > Connect Hardware Keyboard

示例

要运行示例项目,请克隆仓库,然后首先从 Example 目录中运行 pod install

需求

  • Swift 3.0+
  • iOS 8+

安装

CheatCodes 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile

pod "CheatCodes"

作者

Dave Lyon,[email protected]

许可协议

CheatCodes 在 MIT 许可协议下提供。有关更多信息,请参阅 LICENSE 文件。