sterin / vscode-xcodebuild-tools

Work with Xcode projects from inside Visual Studio Code
MIT License
57 stars 9 forks source link

Xcodebuild-tools

Work with Xcode projects from inside Visual Studio Code.

Feedback is highy appreciated! Let me know if this works for you? Are there any showstopping bugs? Any features missing?

Caveats

Features

macOS Example

The subdirectory examples/helloworld contains a working example. Open VScode there.

Alternatively, in a new directory:

  1. Create a new Xcode command line project, with the original name project.

  2. Create a new Xcode workspace named workspace in the same directory. Add the project to the workspace.

  3. Create a new scheme named build inside the workspace and add project to the scheme.

  4. Create a configuration as a file named .vscode/xcodebuild-tools.json:

{
    "workspace": "${workspaceRoot}/workspace.xcworkspace",
    "scheme": "build",
    "variables": {
        "ARG1": "argument 1",
        "ARG2": "argument 2"
    },
    "postBuildTasks": [
        {
            "name": "Sleep for a few seconds",
            "program": "sleep",
            "args": [ "3" ],
            "cwd": "${workspaceRoot}"
        }
    ],
    "debugConfigurations": [
        {
            "name": "test",
            "cwd": "${workspaceRoot}",
            "program": "${buildPath}/project",
            "args": [
                "${ARG1}",
                "${ARG2}"
            ]
        }
    ] 
}
  1. Use xcodebuild-tools command to build, debug, run, clean, switch build configuration, and switch debug configurations.

  2. Use the status bar to build, debug, switch configurations or kill the build.

iOS Example

The subdirectory examples/helloworld-ios contains a working example. Open VScode there.

Alternatively, in a new directory:

  1. Create an iOS example similar to above, but for iOS.

  2. Install ios-sim using npm:

    npm install --global ios-sim
  1. Use a configuration file similar to the following one:
{
    "variables": {
        "SDK_VERSION": "11.4"
    },
    "sdk": "iphonesimulator${SDK_VERSION}",
    "workspace": "${workspaceRoot}/helloworld-ios.xcworkspace",
    "scheme": "build",
    "debugConfigurations": [
        {
            "name": "Simulator",
            "cwd": "${buildPath}",
            "program": "ios-sim",
            "args": [
                "launch", "project.app/",
                "--devicetypeid",  "com.apple.CoreSimulator.SimDeviceType.iPhone-7, ${SDK_VERSION}"
            ]
        }        
    ]
}
  1. Use xcodebuild-tools commands to build and run the project in the simulator.

Credits