0
char*   iperf_get_test_json_output_string ( struct iperf_test* ipt );    // .h file

I am using iperf SDK .c file in iOS project in swift. Above function return (char *) pointer reference. I am getting pointer reference. Anyone Can help to get the string in swift using this above function?

var result =  iperf_get_test_json_output_string(test)
let temp = withUnsafePointer(to: result) {
          $0.withMemoryRebound(to: UInt8.self, capacity: MemoryLayout.size(ofValue: $0) ) {
               String(cString: $0)
           }
2
  • 1
    Is result null terminated? If so, you can simply do temp = String(cString: result) Commented Dec 30, 2022 at 9:17
  • Thank you very much @Ranoiaetep. temp = String(cString: result) is working. Commented Dec 30, 2022 at 11:20

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.