LoginSignup
1
1

More than 3 years have passed since last update.

SwiftのstringからUnsafeMutablePointerに変更

Posted at

Swiftで取得したpathをポインタとしてC++の関数に渡すとき、
pathをStringからUnsafeMutablePointerに変更する必要があります。
具体的下記のようになります。

public func start(aMode: FSRHelperMode, aContinuous: Bool) {

    let inputFile = Bundle.main.path(forResource: "sample", ofType: "pcm", inDirectory: "pcm")
    let carray = inputFile!.cString(using: String.Encoding.utf8)!
    var buffer = UnsafeMutablePointer<CChar>.allocate(capacity: carray.count)
    for i in 0..<carray.count {
        buffer[i] = carray[i]
    }
    Start(_handle, mode, continuous, buffer) //C++関数、bufferの定義はChar *
}
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1