Run swift script from Xcode iOS project as build phase

前端 未结 3 507
梦谈多话
梦谈多话 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: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

提交回复
热议问题