0

I readed some nice articles, tips and answers (here), but I doesn't take this solutions and put it workable in my sourcecode :(

I need to call functions written in C provided in dylib. Without structs it works fine.

typedef struct
{
    uint32_t version;
    OtherType handle;
    const char *pin;
    const char *otherCode;
} cryptParameter;

My not working code is:

var cryptParam = cryptParameter (
  version: 2,
  Handle: cert,
  pin: "123456",
  otherCode: nil
)

The problem for me is to set the const char*with Swift String value. The 123456 do not save in pin. (It compiles, it runs, but value isn't right 123456)

Thanks for answers!

Sébastian
  • 21
  • 4
  • This may help you: https://stackoverflow.com/a/41360939/4763963 – Mo Abdul-Hameed Jul 11 '17 at 18:39
  • [Check out this answer about structs](https://stackoverflow.com/questions/32577808/how-to-create-a-new-instance-of-a-struct-in-c#answer-32582001) – JiFus Jul 11 '17 at 18:50
  • Compare https://stackoverflow.com/questions/40121442/swift-string-literal-assignment-to-c-variable for a similar problem. – Martin R Jul 12 '17 at 18:23

1 Answers1

0

Thank: This code works (only at this position, but it works!)

let cStringValue = "123456".cString(using: .utf8)
cryptParam.pin = UnsafePointer<Int8>(cStringValue)
Sébastian
  • 21
  • 4