问题
I've seen several (well, not that many, but a few) questions here on SO dealing with this error, but none of the proposed solutions worked for me. This is what I get
$ swift
Welcome to Apple Swift version 2.1.1 (swiftlang-700.1.101.15 clang-700.1.81). Type :help for assistance.
warning: Swift error in module repl_swift:
Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.
warning: Swift error in module dyld:
Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.
warning: Swift error in module CoreFoundation:
Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.
...
warning: Swift error in module ServiceManagement:
Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.
warning: Swift error in module libxslt.1.dylib:
Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.
error: Error creating target Swift AST context: (null)
This may or may not have happened after I issued some command that I don't remember (and my bash history does not help very much). The odd thing is that if I uninstall Xcode, the REPL starts working correctly. If I re-install Xcode, however, the errors come back. I'm on Xcode 7.2.1 (7C1002), by the way. Thoughts?
回答1:
To see your current Xcode path:
xcode-select -p
Mine was an old path:
/Applications/Xcode.app/Contents/Developer
Then update this path via:
sudo xcode-select -s /Library/Developer/CommandLineTools
来源:https://stackoverflow.com/questions/35438851/error-creating-target-swift-ast-context-null-in-repl