Can Xcode Use “Folder References” for Code?

前端 未结 4 919
不知归路
不知归路 2021-02-06 22:14

Like many people, I would love to have Xcode use a folder structure that mirrors the folder-structure on disk. However, I cannot get the code in \"folder references\" (the cyan

4条回答
  •  余生分开走
    2021-02-06 22:47

    The simple (and very unfortunate) answer is that Folder References under Xcode remain broken and buggy, they don't work. Tested 04-Mar-2017 in Xcode 8.2.1

    Below is an example exploration so you do not have to waste your time replicating the Xcode failure.

    (incidentally buggy Xcode crashed twice while I was producing this example)

    Per the question, the overall desire is to use a folder reference in Xcode so Xcode picks up all the files in the folder and includes them in the project, and by proxy will update automatically based upon any Finder or Xcode changes of the folder. In this way 50 projects all leveraging the same set of common source code files do not have to be individually updated when those folders get changed. Below explores how this is broken in Xcode (tested in 8.2.1)

    The example: ViewController.m includes NSError+Core.h so we want everything from the folder "NSError+Core" to be added to the project.

    NSError+Core.h is in this centrally located development folder

    Drag the source folder from the Finder into the Project under the "Support" group (nothing up my sleeves, simple drag)

    Xcode dutifully offers to add the drag to the target, note the "Create folder references" is selected, not "Create group references". Note also it is clear that Xcode is offering and is told to add this folder and files to the targets.

    Although everything looks like it should work, the compiler does not pick up the header file and a recompile yields the same results... can't find header. Ditching the DerivedData does not help either.

    So doing a double check, we check the "Compile Sources" under the project and sure enough, the source file is not there either. Remember, Xcode 'added' it to the target...

    So what if we drag it from the folder into the "Support" group...

    It offers to add them to the project again?! Note that the settings are identical to the first time they were drug in by virtue of the parent folder drag instead of files...

    And now the source file shows up in the "Compile Sources" list. Note the bizarre double listing of the files in the project.

    (Xcode crashed shortly after snapping this screen shot)

    And of course the compiler can now find the header file and the error clears on the import as it should have the first time we drug it in...

    Did it just need a little help to "find" the file? If so, the "Create folder references" does exactly what?

    So we try and tidy up and drag the files back from the parent "Supporting Files" group to their rightful folder. Without any confirmation, indication, notification, the files just vanish from the group and nothing happens in the NSError+Core folder.

    Oh by the way, it really did delete them from the project too... The Compile Sources no longer has the NSError+Core.m reference.

    SO to sum up, "Folder references" as implemented thus far do not seem to have any useful purpose... It would appear to be a 6+ year old dunsel on the USS Xcode.

提交回复
热议问题