swiftlang / vscode-swift

Visual Studio Code Extension for Swift
https://marketplace.visualstudio.com/items?itemName=sswg.swift-lang
Apache License 2.0
735 stars 50 forks source link

How to use it with React Native iOS project #507

Closed svipas closed 1 year ago

svipas commented 1 year ago

Hello, I have a question is it possible to use it with React Native iOS project? It uses stuff like project.pbxproj, .xcodeproj, .xcworkspace. There's no Package.swift. You could check out the structure as an example here: https://github.com/react-native-community/rn-diff-purge/tree/version/0.71.4/RnDiffApp/ios. So I'm wondering if it's possible somehow to be able to use VS Code with Swift, because as I tried I do not get any autocomplete, error checking, etc. Even if I create a Package.swift it doesn't work properly. I'm trying to understand how I could make some changes so I could use VS Code to develop Swift. I would appreciate any help!

adam-fowler commented 1 year ago

There isn't a complete solution for iOS yet. We have made some steps towards being able to build iOS products.

Your first issue will be by default VSCode running on macOS is targeting the macOS platform. We have added a command to target different platforms. Press Cmd+Shift+p to bring up the command menu and start typing Select Target Platform until it appears in the list of commands. This is an experimental command that sets up the compiler to target a particular platform. It should show a menu which you can select iOS from.

From this point on you should get symbol completion for iOS symbols. To get symbol completion for your project it'll have to be in a state where it can build. Before building make sure you clean the build to remove any macOS build fragments. Symbols should be available once it has built, which is still quite an ask.

svipas commented 1 year ago

Thank you very much for help, but unfortunately that doesn't work at all. Even though I changed the target to iOS and rebuilt using Xcode it still was the same as previously. I don't have any Package.swift, because we use Pods and some Xcode package dependencies. So maybe that's why? And by building, what do you mean? What I should use to built it, because I used Xcode.

SCR-20230319-smgv

It doesn't even work if I try to use methods from a different file, it still shows <<error type>>

adam-fowler commented 1 year ago

You need a Package.swift and to have compiled it in VSCode

svipas commented 1 year ago

Could you help me setup Package.swift what it should contain? Or I could use just a basic one? Also, to have it compiled in VS Code you mean using task swift build?

adam-fowler commented 1 year ago

Yes use the swift build task in VSCode. I have no idea about the structure of your project so can't help you with setting up a Package.swift. But because you are using a bunch of Pods I don't think you are going to have any luck.

This extension is here primarily to support situations where Xcode is unavailable ie non Apple platforms. It is centred around SwiftPM because that is the package manager used on those platforms. There are no plans to support xcodeproj files, or CocoaPods. Some people have managed to get simple apps compiling with VSCode and SwiftPM but it involves a lot of messing about. You'll need to search on the web for articles though. There might be some posts on https://forums.swift.org as well