Classes in Swift files inside folder references not seen by Xcode 10's compiler

好久不见. 提交于 2019-12-13 03:36:02

问题


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.

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.

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.

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

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


回答1:


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:

  • a group (yellow with a red mark in the lower corner)
  • or, a folder-linked group (yellow plain and simple)

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.

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.



来源:https://stackoverflow.com/questions/52484234/classes-in-swift-files-inside-folder-references-not-seen-by-xcode-10s-compiler

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!