Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode run script with Swift

Tags:

xcode

swift

I have a run script in Xcode that I have written in 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. 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'

:0: Could not build Objective-C module 'CoreFoundation'

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

Any ideas why this is?

like image 932
Brandon Williams Avatar asked May 04 '15 22:05

Brandon Williams


1 Answers

It's using the iOS device SDK by default (iPhoneOS). Try to invoke xcrun by specifying either the iphonesimulator or macosx SDKs like this:

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

#!/usr/bin/xcrun --sdk macosx swift
like image 130
Javier Soto Avatar answered Sep 24 '22 15:09

Javier Soto