FLEX

repository·master·Indexed 12 days ago

https://github.com/flextool/flex

An in-app debugging tool for iOS that allows developers to explore view hierarchies, network history, heap objects, and SQLite databases. It supports installation via CocoaPods, Carthage, and Swift Package Manager for apps targeting iOS 9 or higher.

Tokens
1.4K
Snippets
4
Records
8
Agent score
47%

What's inside FLEX

  1. Parsing JSON in FLEX fields and NSUserDefaults

    master

    When setting fields of type id or values in NSUserDefaults via FLEX, the tool attempts to parse the input string as JSON. This allows you to provide complex data structures like arrays and dictionaries using strings.

    • Complex Types: Use JSON syntax for arrays and dictionaries.
    • Strings: To set a literal string value, you must wrap it in quotes (e.g., "value").
    • Explicitly Typed Strings: For ivars or properties explicitly typed as NSStrings, quotes are not required.
  2. Exclude FLEX from Release builds (Manual Integration)

    master

    If you have added FLEX files manually to your Xcode project, you can exclude them from production builds via Xcode settings:

    1. Navigate to Build Settings.
    2. Locate Build Options > Excluded Source File Names.
    3. For the Release configuration, set the value to FLEX* to exclude all files with the FLEX prefix.
  3. Exclude FLEX from Release (App Store) builds

    master

    FLEX is a debugging tool and should not be included in production App Store builds. Depending on your integration method, use the following strategies to ensure FLEX is only present in Debug builds.

    General Code Practice

    Wrap all code where you integrate FLEX with an #if DEBUG statement to prevent errors in Release builds and ensure the tool is inaccessible to users.

    CocoaPods

    Specify the Debug configuration for the FLEX pod in your Podfile:

    pod 'FLEX', :configurations => ['Debug']

    Carthage

    1. Do NOT add FLEX.framework to your target's embedded binaries.
    2. Add $(PROJECT_DIR)/Carthage/Build/iOS to your target's Framework Search Paths.
    3. Add a Run Script Phase (after Link Binary with Libraries) to embed the framework only during debug builds:
    if [ "$CONFIGURATION" == "Debug" ]; then
      /usr/local/bin/carthage copy-frameworks
    fi

    Ensure $(SRCROOT)/Carthage/Build/iOS/FLEX.framework is added as an input file to this script phase.

    Swift Package Manager

    In Xcode, navigate to Build Settings > Build Options > Excluded Source File Names. For your Release configuration, set the value to FLEX* to exclude all files starting with the FLEX prefix.

  4. Use FLEX keyboard shortcuts in the Simulator

    master

    When running in the iOS Simulator, you can use the following default keyboard shortcuts to interact with FLEX:

    • f: Toggle the FLEX toolbar.
    • ?: Show a full list of available shortcuts.
    • Esc: Close active modals.
    • Arrow Keys: Scroll through content.
    • 3D Touch Simulation: Use combinations of Command, Control, and Shift keys. Each key contributes 1/3 of the maximum possible force. Note that you must move the touch slightly to see pressure updates.
  5. Install FLEX via CocoaPods, Carthage, or Swift Package Manager

    master

    FLEX requires an app targeting iOS 9 or higher. Choose the installation method that matches your project's dependency manager.

    CocoaPods

    Add the following to your Podfile. It is recommended to restrict FLEX to Debug configurations to prevent it from being included in production builds.

    Carthage

    Add the following to your Cartfile:

    Swift Package Manager

    Add the repository URL to your Package.swift dependencies and include FLEX in your target's dependencies.

    # CocoaPods
    pod 'FLEX', :configurations => ['Debug']
    # Carthage
    gitub "flipboard/FLEX"
    // Swift Package Manager
    dependencies: [
        .package(url: "https://github.com/FLEXTool/FLEX.git", .upToNextMajor(from: "4.3.0"))
    ]
    
    // In your target
    .target(
        name: "YourDependency",
        dependencies: [
            "FLEX"
        ]
    )
  6. Handling exception breakpoints while using FLEX

    master

    FLEX uses certain functions (such as NSGetSizeAndAlignment()) that throw exceptions when they encounter unhandleable input. FLEX catches these exceptions internally to prevent the app from crashing, but if you have exception breakpoints active in Xcode, the debugger will stop at these points.

    Recommendation: You may want to disable exception breakpoints while actively using FLEX to avoid unnecessary interruptions.

  7. Show the FLEX explorer programmatically

    master

    You can trigger the FLEX toolbar to appear within your application using the FLEXManager singleton. It is highly recommended to wrap these calls in #if DEBUG blocks to ensure the debugging tools are never accessible in production builds.

    // Objective-C
    [[FLEXManager sharedManager] showExplorer];
    // Swift
    FLEXManager.shared.showExplorer()
  8. Register custom simulator keyboard shortcuts

    master

    You can extend FLEX by adding your own custom keyboard shortcuts to the simulator using the registerSimulatorShortcutWithKey:modifiers:action:description: method on FLEXManager.

    ```objc
    // Example usage pattern
    [FLEXManager sharedManager] registerSimulatorShortcutWithKey:someKey 
                                                     modifiers:someModifiers 
                                                       action:someSelector 
                                                    description:@