Skip to content

Instantly share code, notes, and snippets.

@terhechte
Last active June 24, 2018 18:47
Show Gist options
  • Save terhechte/3cc8ad46ec77fa0bd99aad77cbb71622 to your computer and use it in GitHub Desktop.
Save terhechte/3cc8ad46ec77fa0bd99aad77cbb71622 to your computer and use it in GitHub Desktop.
Run Cocoapods from Swift
func runCocoaPods() {
DispatchQueue.global(qos: .userInitiated).async {
let process = Process()
// The trick is launching a proper login shell that hosts the task in question
// so that the environment is being initialized correctly
// `-l` forces a login shell
// `-c` tells bash to run a specific command automatically
process.launchPath = "/bin/bash"
process.currentDirectoryPath = "/Users/terhechte/Dev/tmp/testRunCocoaPods"
process.arguments = [
"-l",
"-c",
"pod search --no-ansi --simple afnetworking"
]
let outputPipe = Pipe()
process.standardOutput = outputPipe
process.launch()
guard let output = String(data: outputPipe.fileHandleForReading.readDataToEndOfFile(), encoding: .utf8) else {
return
}
print(output)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment