Last active
August 27, 2018 20:19
-
-
Save dduan/20534149ca788882475ae0c5925a3eba to your computer and use it in GitHub Desktop.
A function that turns a Swift 3 [String] to an array of C strings (char *[]).
This file contains 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 withCStrings(_ strings: [String], scoped: ([UnsafeMutablePointer<CChar>?]) throws -> Void) rethrows { | |
let cStrings = strings.map { strdup($0) } | |
try scoped(cStrings + [nil]) | |
cStrings.forEach { free($0) } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment