mac安装多个Xcode

  • 安装多个Xcode,可以在Xcode下载页面查询下载各个版本的Xcode,下载安装
  • 需要注意的是下载解压后的XCode放入指定的目录,需要注意命名,如果使用XCode15.x这种命名,在编译时有可能出现swiftheader的编译问题,swiftbridge相关的头文件无法查询,根据分析,只能在XCode.app/Content下才能索引,所以使用哪个XCode,就应该将它命名为XCode.app
  • 使用Xcode-select进行当前Xcode的选择
    在这里插入图片描述-可以通过Xcode-select和xcodebuild指令来确认切换是否成功
    Xcode-select -p 在这里插入图片描述
    gcc --version在这里插入图片描述
    xcodebuild -version
    在这里插入图片描述

网上也有用脚本实现的,但基于XCode命名问题,编译可能出现问题

change_xcode_version()
{
    [ "$1" != "11" -a "$1" != "13" ] && echo "input is $1,not 11 or 13" && exit 1
    xcode_v=$1
    echo "xcode version:"
    xcodebuild -version
    [ "$1" == "11" ] && export DEVELOPER_DIR=/Applications/Xcode/11.4/Xcode.app/Contents/Developer
    [ "$1" == "13" ] && export DEVELOPER_DIR=/Applications/Xcode/13.1/Xcode.app/Contents/Developer
    ./expect_xcode $1  # 调用切换Xcode版本的脚本
    sleep 10
    xcodebuild -version
    # 检查DEVELOPER_DIR是否切换成功,否则异常退出
    xcode_ver=`xcodebuild -version |grep Xcode |awk -F " " '{print $2}'`
    [ "$1" == "11" ] && [ "$xcode_ver" != "11.4" ] && echo "xcode version $xcode_ver, not 11.4" && exit 1
    [ "$1" == "13" ] && [ "$xcode_ver" != "13.1" ] && echo "xcode version $xcode_ver, not 13.1" && exit 1
    echo "new xcode version:"
    xcodebuild -version
}

#!/usr/bin/expect

set timeout 10
set version [lindex $argv 0]
set password "123456"  # 开机密码

if {$version == "13" } {
    spawn sudo xcode-select -s /Applications/Xcode/13.1/Xcode.app/Contents/Developer
}
if {$version == "11" } {
    spawn sudo xcode-select -s /Applications/Xcode/11.4/Xcode.app/Contents/Developer
}
expect "*assword*" {send "$password\r"}  # 自动输入密码
interact

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值