Xcode自动完成功能在Swift游乐场的Sources文件夹中不起作用 [英] Xcode autocomplete does not work in Sources folder of Swift playgrounds

查看:140
本文介绍了Xcode自动完成功能在Swift游乐场的Sources文件夹中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一个Swift操场上工作,该操场在Sources文件夹中与主文件一起包含多个文件.当在主文件中键入某些内容(例如"UI")时,我会得到预期的自动完成建议.但是,当我在Sources文件夹中的文件中执行相同的操作时,我得到一个哑"自动完成菜单,如以下问题所示:

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

我已经尝试按照上述问题中的建议删除DerivedData,甚至完全重新安装了Xcode.但是,问题并没有消失.我创建了一个新的游乐场,以确保它不是特定于此项目的,并且会发生相同的问题.

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.

我只是在另一台Mac上尝试了相同的操作,并且发现了相同的问题.我想这只是Xcode中的错误,与特定的安装或项目无关.

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.

推荐答案

为了启用自动补全功能,您可以将Playground嵌入到常规Xcode项目(例如iOS应用程序)中.我建议为此目的创建一个虚拟项目.只需将您的游乐场拖放到该虚拟项目中,并确保选中添加到目标".

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".

然后您可以导航到

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.

在此过程之后,将针对该虚拟目标构建所有源文件,并且您可以照常使用自动完成功能.据我所知,这是目前调试Playgrounds的最佳实践.无论如何,我想知道是否有更简单的方法来实现这一目标.

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.

这篇关于Xcode自动完成功能在Swift游乐场的Sources文件夹中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆