0

I am trying to use python interpreter in swift. But it is written in C and thus I have created a bridge between ObjC and Swift. Method in C accepts char * and when I try to pass string to method it says that it accepts only UnsafeMutablePointer. I am trying to convert it like this

let str = "Hello" as NSString
var buffer = UnsafeMutablePointer<Int8>(str.utf8String)

but Swift compiler says,Cannot invoke initializer for type 'UnsafeMutablePointer' with an argument list of type '(UnsafePointer?)'. What is the proper way of using C data types in Swift and how to solve this problem?

rmaddy
  • 314,917
  • 42
  • 532
  • 579

1 Answers1

1

It seems to be a duplicate from Here. You can simply use

let str = "Hello"
let buffer = str.cString(using: .utf8)