複数のSwiftバージョンの違うXcodeをインストールした状態でアプリをビルドすると
Module compiled with Swift 5.x.x cannot be imported by the Swift 5.x compiler
のエラーが発生することがあります(xのところは具体的なバージョン)。これはCarthageのモジュールとXcodeでビルドしようとしているもののSwiftバージョンが異なりますというエラーです。
その場合はCarthageのビルドを使いたいXcodeのSwiftバージョンに合わせなければなりません。
その際はxcode-select
コマンドを使います。
sudo xcode-select -switch /Applications/Xcode-beta.app/Contents/Developer
のようにxcode-selectコマンドでCarthageが見るXcodeの向き先を変えてあげます。
念の為に、変更前に現在のpathを確認したい場合は
sudo xcode-select -p
で現在のpathがわかるので、戻したい場合は現在のpathをメモっておくと安心です。