Last active
June 24, 2018 18:47
-
-
Save terhechte/3cc8ad46ec77fa0bd99aad77cbb71622 to your computer and use it in GitHub Desktop.
Run Cocoapods from Swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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