DEV Community

Cover image for iOS Development in VS Code
balrajOla
balrajOla

Posted on

iOS Development in VS Code

Summary

The article discusses enabling iOS development on Visual Studio Code (VSCode), an alternative to Xcode, particularly useful for developers who want cross-platform support on systems like Linux and Windows, as well as features like Live Share for real-time collaboration. It outlines the steps required to configure VSCode for Swift and iOS development by enabling Swift support, adding iOS frameworks, and supporting app targets, emphasizing that while Xcode is essential, VSCode can enhance the development experience.

Key Points

Overview of iOS Development on VSCode

  • Apple is increasingly supporting Swift on platforms beyond macOS, including Linux, Windows, and cloud environments.
  • VSCode is becoming a viable option for iOS development, offering unique collaboration features that Xcode lacks.

Reasons to Use VSCode Over Xcode

  • Xcode is not available for Linux and Windows, limiting cross-platform development.
  • Features like Live Share allow for real-time collaborative coding, akin to Google Docs for documents, enhancing pair programming and remote collaboration.

Steps to Enable iOS Development in VSCode

  1. Enable Swift Language Support

    • Ensure Xcode and VSCode are installed.
    • Use the command $ xcrun sourcekit-lsp to confirm SourceKit-LSP is functioning correctly.
  2. Build the SourceKit-LSP Extension

    • Clone the SourceKit-LSP repository:
     $ git clone https://github.com/apple/sourcekit-lsp.git
     $ cd sourcekit-lsp/Editors/vscode/
     $ npm run createDevPackage
     $ code --install-extension out/sourcekit-lsp-vscode-dev.vsix
    
  • Restart VSCode after installation.
  1. Configure the Extension

    • Open settings.json in VSCode and add the following to specify the path to the SourceKit-LSP executable:
     "sourcekit-lsp.serverPath": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/sourcekit-lsp"
    

Adding iOS Framework Support

  • Insert the following configuration in settings.json to enable import of iOS frameworks like UIKit:
  "sourcekit-lsp.serverArguments": ["-Xswiftc", "-sdk", "-Xswiftc", "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk", "-Xswiftc", "-target", "-Xswiftc", "x86_64-apple-ios13.6-simulator"]
Enter fullscreen mode Exit fullscreen mode

Supporting App Targets

  • To work on iOS apps rather than just Swift packages, create a dummy Package.swift file in the root directory to satisfy SourceKit-LSP's requirements:
  // swift-tools-version:5.2
  import PackageDescription

  let packageName = "PROJECT_NAME" // <-- Change this to yours

  let package = Package(
      name: packageName,
      products: [
          .library(name: packageName, targets: [packageName])
      ],
      targets: [
          .target(name: packageName, path: packageName)
      ]
  )
Enter fullscreen mode Exit fullscreen mode
  • Make sure to replace PROJECT_NAME with the actual name of your project.

Conclusion

  • After following these steps, restart VSCode, and you should have proper UIKit auto-completion, allowing developers to utilize VSCode as a functional IDE for iOS development.

Top comments (0)