Xcode 10的编译器看不到的文件夹引用中的Swift文件中的类 [英] Classes in Swift files inside folder references not seen by Xcode 10's compiler

查看:282
本文介绍了Xcode 10的编译器看不到的文件夹引用中的Swift文件中的类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个包含近1K个Swift文件的项目.如果所有内容都在组中,则效果很好,但是当尝试向包含Swift文件的目录中添加一些文件夹引用时,编译器只是看不到这些文件中定义的任何内容(例如,类).它适用于捆绑软件和数据文件,但不适用于源代码.

We have a project with nearly 1K Swift files. It just works well if everything is inside groups, but when trying to add some folder references to directories that contain Swift files, the compiler just can't see any thing defined inside these files (classes, for example). It works well for bundle and data files, but not for source code.

我还尝试使用不同的方法(拖动,使用菜单和手动浏览等)将现有组更改为文件夹,并且XCode停止查看在这些Swift文件夹的文件中声明的实体.当我将同一文件夹切换回一个组时(删除->删除引用->将文件添加到项目...),它将再次起作用.

I also tried changing existing groups to folders using different methods (dragging, using the menu and manually browsing, etc.) and XCode stops seeing the entities declared inside these Swift folders' files. When I switch the same folder back to a group (delete -> remove reference -> add files to project...), it works again.

请注意,我已打开文件检查器,并且已确保已检查参考文件夹的目标.还尝试取消选中它,然后再次检查,以防万一添加文件时出现另一个XCode错误.什么都没用.

Please note that I opened the File Inspector, and already ensured that the target for the reference folder was checked. Also tried to uncheck it and checked again, just in case there is just-another-XCode-bug when adding files. Nothing worked.

我做过的另一个实验是将文件夹移动到根目录,因此该文件夹不在组中.也没用.

Another experiment that I've done was consisted of moving a folder to the root directory, so the folder was not inside a group. Didn't work either.

每次尝试后,我总是清理项目的build文件夹,以防万一.

After each try, I always cleaned the project's build folder, just in case.

请注意,以下问题并未提供解决此问题的有用提示:

Please note that the following questions did not provide anything useful tip for fixing this:

  • Xcode added folder in blue and related there files are not compiling
  • Moving Files into a Real Folder in Xcode

当然,由于我想要文件夹而不是组,因此这对我来说是没有意义的,因为考虑到该特定项目的大量Swift文件,我发现它们更易于使用,并且特别易于维护: 未正确添加将文件夹添加到Xcode项目

And of course, this another one does not make sense to me since I want folders, not groups, because I find them much easier to use and specially, to maintain, given the large amount of Swift files of this particular project: Adding Folder to Xcode Project is not Properly added

推荐答案

它适用于捆绑软件和数据文件,但不适用于源代码.

It works well for bundle and data files, but not for source code.

是的,那是因为它们是完全不同的事物,需要以完全不同的方式进行处理.

Yup, well, that's because those are completely different kinds of thing, and need to be treated in completely different ways.

您不能将代码放入文件夹引用(蓝色)中.那只是意味着将代码文件复制到应用程序主体中",这很愚蠢.这就是您要使用捆绑软件和数据文件进行的事情.

You can't put code inside a folder reference (blue). That would simply mean "copy this code file into the body of the app", which would be silly. That's the kind of thing you would do with bundle and data files.

如果问题是要在项目窗口中组织您的代码文件引用,则可以使用:

If the problem is to organize your code file references within the project window, you can use:

  • 一组(在底角带有红色标记的黄色)
  • 或者,一个文件夹链接的组(黄色,简单明了)

在后一种情况下,代码文件本身也将放置在项目窗口内磁盘上的相应文件夹中,因此,这也是磁盘上的组织方式.

In the latter case, the code file itself will also be placed in the corresponding folder on disk inside the project window, so this is also a mode of organization on disk.

注意,但是请注意,您必须始终让Xcode本身来组织项目文件夹的内容!您必须完全在项目窗口的项目"检查器中工作.远离Finder.否则,您将破坏您的项目.

NOTE But note that you must always let Xcode itself organize the contents of the project folder! You must work entirely within the Project inspector in the project window. Stay out of the Finder. Otherwise, you'll break your project.

这篇关于Xcode 10的编译器看不到的文件夹引用中的Swift文件中的类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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