Run swift script from Xcode iOS project as build phase

前端 未结 3 511
梦谈多话
梦谈多话 2021-02-01 05:20

Here is a simple swift script:

#!/usr/bin/env xcrun swift

import Foundation

let task = NSTask()
task.launchPath = \"/bin/echo\"
task.arguments = [\"farg1\", \"         


        
相关标签:
3条回答
  • 2021-02-01 05:33

    If you unset the SDKROOT environment variable before calling the swift script, it will then use the OS X sdk.

    0 讨论(0)
  • 2021-02-01 05:54

    When building for iOS the implicit SDK for xcrun is the iOS SDK, so you have the change it to the Mac OS X SDK with a command line parameter. Change the first line in your script to:

    #!/usr/bin/env xcrun --sdk macosx swift
    
    0 讨论(0)
  • 2021-02-01 05:54

    +1 for @Mats's answer.

    For anyone who get an error like *** is only available on OS X 10.11 or newer.

    You can:

    #!/usr/bin/env xcrun --sdk macosx swift -target x86_64-macosx10.11
    

    UPDATE 1:

    If you don't get ready for Swift 3, but you are using Xcode 8, you can also control toolchain version:

    xcrun --toolchain com.apple.dt.toolchain.Swift_2_3 -f swift
    

    So:

    #!/usr/bin/env xcrun --toolchain com.apple.dt.toolchain.Swift_2_3 --sdk macosx swift -target x86_64-macosx10.11
    

    also checkout answers here: https://stackoverflow.com/a/36254848/1298043

    0 讨论(0)
提交回复
热议问题