Xcode Unit Test build error “Unexpected '@'

2019-09-09 16:12发布

问题:

Trying to build a unit test (XCTest) and get the following error in several files:

@import Foundation; =======> Unexpected '@' in program

@import UIKit; =======> Unexpected '@' in program

(etc.)

I do not get this compile error for the regular build, only unit tests. What seem really odd to me is that the source files that are generating the errors are not even part of the unit test Compile Sources in Build Phases! (not needed for unit testing)

What is the conflict?

回答1:

Please check if you enabled "Enable Modules" in your test target build settings.