简体   繁体   English

Xcode用Swift运行脚本

[英]Xcode run script with Swift

I have a run script in Xcode that I have written in Swift. 我在Xcode中有一个运行脚本,我在Swift中编写过。 In the build settings I have a run script whose shell is set to /bin/sh and the contents is the single line ./my-script.swift . 在构建设置中,我有一个运行脚本,其shell设置为/bin/sh ,内容是单行./my-script.swift That file contains only the lines: 该文件只包含以下行:

#!/usr/bin/xcrun swift
import Foundation

If I build for the simulator, everything works just fine. 如果我为模拟器构建,一切正常。 If I build for the device I get a ton of errors along the lines of: 如果我为设备构建,我会遇到大量错误:

/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.3.sdk/System/Library/Frameworks/CoreFoundation.framework/Headers/CoreFoundation.h:11:10: Could not build module 'Darwin' /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.3.sdk/System/Library/Frameworks/CoreFoundation.framework/Headers/CoreFoundation.h:11:10:无法构建模块'达尔文'

:0: Could not build Objective-C module 'CoreFoundation' :0:无法构建Objective-C模块'CoreFoundation'

/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.3.sdk/usr/include/sys/cdefs.h:680:2: Unsupported architecture /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.3.sdk/usr/include/sys/cdefs.h:680:2:不支持的架构

Any ideas why this is? 任何想法为什么会这样?

It's using the iOS device SDK by default ( iPhoneOS ). 它默认使用iOS设备SDK( iPhoneOS )。 Try to invoke xcrun by specifying either the iphonesimulator or macosx SDKs like this: 尝试通过指定iphonesimulatormacosx SDK来调用xcrun,如下所示:

#!/usr/bin/xcrun --sdk iphonesimulator swift

#!/usr/bin/xcrun --sdk macosx swift

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM