i using framework vendor made in c, framework has following struct:
typedef struct ttinfo { int size; const char* vid; const char* cid; const char* cmm; const char* ckey; } tinfo;
which gets imported swift such:
public struct ttinfo { /**< \brief size of structure */ public var size: int32 /**< \brief pointer null-terminated string*/ public var vid: unsafepointer<int8> /**< \brief pointer null-terminated string*/ public var cid: unsafepointer<int8> /**< \brief pointer null-terminated string. may null. */ public var cmm: unsafepointer<int8> public var ckey: unsafepointer<int8> public init() public init(size: int32, vid: unsafepointer<int8>, cid: unsafepointer<int8>, cmm: unsafepointer<int8>, ckey: unsafepointer<int8>) } public typealias tinfo = ttinfo
to tried use in swift as:
var ci:tinfo = tinfo(size: sizeof(tinfo), vid: "vid", cid: "cid", cmm: nil, ckey: "ckey")
and gets passed following function in header
public func ti(ci: unsafemutablepointer<tinfo>, _ reserved: unsafemutablepointer<void>, _ flags: int32) -> tt
as such:
ti(&ci, nil, initoptions)
now compiler gives me no errors code, neither crashes when runs, however, framework when using code in swift returns me error.
my questions are:
is initialisation of struct correct, think wrong cant longer print contents of ci pointer values? if wrong how can correct it?
i seen in several places size of struct should use sizeof(tinfo) others strideof because of padding still isnt clear me when apply both return same size.
would appreciate this. btw using swift2.3
edit:
thanks link shared @amomchilov in post setting each struct property cchar before passing struct worked, such as:
("vid" nsstring).utf8string
you need call utf8string
necessary unsafepointer<int8>
, null-termianted string:
import foundation var ci:tinfo = tinfo(size: sizeof(tinfo), vid: "vid".utf8string, cid: "cid".utf8string, cmm: nil, ckey: "ckey".utf8string)
Comments
Post a Comment