How to locate ios sdk in VSCode using Swift plugin

I'm opening a single swift file without Package.swift:

import AppKit
import UIKit

When I use go to definition feature provided by Swift plugin, I can go to definition of AppKit and NSView, but cannot go to UIKit and UIView.

The definition of NSView is at MacOSX.platform/..., while UIView should be at iPhoneOS.platform/..., but swift just cannot go to definition of UIView

Am I missing some setting of Swift plugin? I've tried set the Runtime Path but doesn't work.

The VSCode extension is not really designed for iOS development. iOS development requires features that are only available in Xcode.

But you can get some of the way by setting Swift: SDK. The easiest way to get this correct is use the command Swift: Select Target Platform.... With this you will get symbol completion for the symbols in the SDK you select.

It will also attempt to use that SDK when building, but that produces undefined results.

1 Like

You can try xcode-build-server [1] tool that parses build logs and provides build flags for Swift LSP server. Additionally you can try my VSCode extension that integrates with different tools like xcodebuild, swift-format, xcode-build-server and so on to make development of iOS/Swift applications in VSCode little bit easier.

  1. GitHub - SolaWing/xcode-build-server: a build server protocol implementation for integrate xcode with sourcekit-lsp
  2. GitHub - sweetpad-dev/sweetpad: Develop Swift/iOS projects using VSCode

Thanks! It works for me! Selecting target platform to iOS totally solved my problem.

Thanks! In fact I made a similar command line tool that do the similar things to your sweetpad:

Saafo/xcode-project-manager: Manage Xcode projects with ease

But your extension is more completely and easy to use in VSCode, I've download it!