Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode autocomplete does not work in Sources folder of Swift playgrounds

I am working on a Swift playground that contains multiple files in the Sources folder alongside the main file. When I type something, for instance, "UI", in the main file, I get the expected autocomplete suggestions. However, when I do the same in files in the Sources folder, I get a "dumb" autocomplete menu as seen in this question: Xcode 9 Autocomplete Not Working 100% - Partially Working

I have tried deleting DerivedData as suggested in the above question, and have even gone to the lengths of reinstalling Xcode entirely. However, the problem has not gone away. I have created a new playground to ensure it is not specific to this project, and the same problem occurs.

Edit: I just tried the same thing on a different Mac and the same problem was observed. I suppose this is simply a bug in Xcode that has nothing to do with this particular installation or project.

like image 672
brendon-ai Avatar asked Feb 04 '18 22:02

brendon-ai


People also ask

Why is autocomplete not working Xcode?

This can happen when the file is not a member of the Target. Open the file where autocomplete is not working and show the the "Utilities" tab in the top right of Xcode (blue in the screenshot below). Ensure your Target (typically your app's name) is checked.

Does Xcode have autocomplete?

Xcode 14 comes to remove this unwanted friction, as it can now auto-complete all that necessary code in just a few moves. As a result, we are becoming able to get finished with such tasks within seconds, and that's a great benefit for the overall implementation process.

What is the difference between Swift playground and Xcode?

One of the biggest differences between Swift Playgrounds and Xcode Playgrounds is that Swift Playgrounds are much less powerful and are built more as an educational tool. My biggest fear is that as Apple brings Swift Playgrounds to the Mac that they will stop supporting and growing Xcode Playgrounds.


1 Answers

In order to enable autocompletion, you can embed your Playground in a regular Xcode project (e.g. an iOS application). I recommend creating a dummy project for that purpose. Simply drag and drop your playground in this dummy project and make sure to check "Add to target".

Then you can navigate to

Target -> Build Phases -> Compile Sources -> + -> Add other

and add all the files from your source folder. Please note, that you don't need to actually copy the files, a reference is enough for this purpose.

After this process all your source files are built against this dummy target and you can use autocompletion as usual. As far as I know, this is the best practice for debugging Playgrounds right now. Anyway I am curious, if there is an easier way to achieve that.

like image 87
JoRa Avatar answered Oct 18 '22 22:10

JoRa