I'm calling a C library from Swift 4 and I have troubles converting a [String]
to const char *[]
.
The C API defines this method:
int getDREFs(const char* drefs[], unsigned char count);
which is exposed in Swift as
public func getDREFs(_ drefs: UnsafeMutablePointer<UnsafePointer<Int8>?>!, _ count: UInt8) -> Int32
The Swift wrapper I'm trying to write is the following
public func get(drefs: [String]) throws {
var cDrefs = [UnsafePointer<Int8>]()
for dref in drefs {
cDrefs.append(dref.cString(using: .utf8)!)
}
let pDrefs = UnsafeMutablePointer<UnsafePointer<Int8>>(&cDrefs)
getDREFFs(pDrefs, drefs.count)
}
but the error I get is
Cannot convert value of type 'UnsafeMutablePointer<UnsafePointer<Int8>>' to expected argument type 'UnsafeMutablePointer<UnsafePointer<Int8>?>!'
what am I missing?