对SwiftUI怀有极大的好奇心,先是升级了Xcode11beta版,就迫不及待的创建了SwiftUI的工程,本以为会一切顺利,结果坑还是不有的,现总结如下:
1、创建SwiftUI后发现画布不展示(画布是swiftUI新的功能,即可以事实查看界面),ps:我当前的系统是莫哈维Mojave10.14.5。查看苹果官方文档后,发现SwiftUI需要将系统升级到10.15,而现在只有beta版的,ok,升级为beta10.15版系统
2、升级完系统,这下画布出现了,但是画布编译报错 failed to build ContentView.swift,点击右侧的Diagnostics进行诊断,结果如下:
invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
----------------------------------------
failedToCodeSign: xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
/Users/yangyangzi/Library/Developer/Xcode/DerivedData/CreatingAndCombiningViews-ftgpsvdswgizgqgyfzdaoirbhbey/Build/Intermediates.noindex/Previews/Landmarks/Intermediates.noindex/CreatingAndCombiningViews.build/Debug-iphonesimulator/Landmarks.build/Objects-normal/x86_64/ContentView.2.preview-thunk.dylib: the codesign_allocate helper tool cannot be found or used
解决方法:安装xcode命令行工具:command line tools
安装过程如下:
2.1》打开终端,输入如下命令:xcode-select --install 按回车
2.2》根据弹框提示选择 安装-》同意许可 即可安装
2.3》安装完成后在终端在此执行命令xode-select --install,出现以下情况,则说明安装成功
xcode-select: error: command line tools are already installed, use "Software Update" to install updates
yangyangzideMacBook-Air:~ yangyangzi$ sudo xcodebuild -license
安装好xcode命令行工具,再点击画布的resume,这下画布就能正常展示了