我使用的是一个由C制造的供应商提供的框架,这个框架有以下结构:
typedef struct tTINFO {
int size;
const char* vId;
const char* cId;
const char* cmm;
const char* cKey;
} TINFO;就像这样被导入到which中:
public struct tTINFO {
/**< \brief Size of the structure */
public var size: Int32
/**< \brief Pointer to a null-terminated string*/
public var vId: UnsafePointer<Int8>
/**< \brief Pointer to a null-terminated string*/
public var cId: UnsafePointer<Int8>
/**< \brief Pointer to a null-terminated string. May be 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我试图迅速地将其用作:
var cI:TINFO = TINFO(size: sizeof(TINFO),
vId: "vID",
cId: "cID",
cmm: nil,
cKey: "cKey")并将其传递给报头中的以下函数
public func TI(CI: UnsafeMutablePointer<TINFO>, _ Reserved: UnsafeMutablePointer<Void>, _ Flags: Int32) -> TT因此:
TI(&cI, nil, initOptions)现在编译器给我的代码没有错误,它在运行时也不会崩溃,但是在使用此代码时,框架会返回一个错误。
我的问题是:
如果能帮上忙就好了。顺便说一下,我用的是迅捷2.3
编辑:
由于@AMomchilov在此post中共享的链接,在将每个struct属性传递给结构之前将其设置为CChar,如下所示:
("vID" as NSString).UTF8String发布于 2016-08-02 02:15:36
您需要调用utf8String来获得必要的UnsafePointer<Int8>空条件字符串:
import Foundation
var cI:TINFO = TINFO(size: sizeof(TINFO),
vId: "vID".utf8String,
cId: "cID".utf8String,
cmm: nil,
cKey: "cKey".utf8String)https://stackoverflow.com/questions/38703398
复制相似问题