问题
Create an App, Single View is ok, with Unit Tests.
In the App Target: Create a Class with a property and a function. Create another class and function. Write some code to reference class 1 property. Autocomplete not showing the property or function, but, if the property/function is written correctly, it is flagged by code sense and compiles. [NOTE: I've since worked this out. It would seem I have to manually save changes to a file and then AC works - I'm sure I didn't need to do this in Xcode 8 but now I'm not sure!!]
In the Test Target: Add @testable import App module to dummy test. Start writing code to reference class 1. Autocode is not showing it. Complete the line of code and the compiler is flagging that the class doesn't exist. Check syntax and it is correct, just that the compiler flagging as error.
In App target create a group, move class 1 into group and the Test now compiles correctly.
Basically, it would seem that the indexer isn't running properly - that's my best guess. Sometimes, restarting Xcode resolves this - anything that makes the indexer run resolves it actually (hence moving the class into another group fixes it.)
My TDD cycle at the moment:
- Write a failing test
 - Write code to make test pass: new class/property/function
 - Quit Xcode
 - Start Xcode
 - Hope that works!
 - Run tests
 
Crazy! Note that cleaning/building/deleting derived data does not solve the problem.
If I add the class to the Test Target, then it works but I thought the point of using @testable was to avoid this - it's worth noting that flagging a property or function as Public doesn't help, the only things that work are forcing an index or adding the class to the Test Target.
Have I inadvertently set some configuration value somewhere - certainly haven't done it myself through the terminal - or any ideas at all?
来源:https://stackoverflow.com/questions/46600071/xcode-9-not-linking-indexing-correctly