Here is a simple swift script:
#!/usr/bin/env xcrun swift
import Foundation
let task = NSTask()
task.launchPath = "/bin/echo"
task.arguments = ["farg1", "arg2"]
let pipe = NSPipe()
task.standardOutput = pipe
task.launch()
let data = pipe.fileHandleForReading.readDataToEndOfFile()
let output: String = NSString(data: data, encoding: NSUTF8StringEncoding)
print(output)
I added this script as build phase(before 'compile sources phase) in iOS project but XCode failed to build project with error 'undefined NSTask()...' When I added same script in OSX project, XCode build project without any errors.
Question is why XCode is looking for NSTask inside iOS framework(where doesn't exists) instead to run swift script as platform script(like bash)?
Just to add: swift script isn't included into project with other files to compile. It's just added into build phase, even before compilation, of other source files(which are objective-c files) to run it.
Any ideas how to run custom swift script from iOS XCode project when script contains classes which aren't part of iOS framework?