我正在尝试在 Swift 3.0 中使用 strlcpy,但不断收到错误消息“无法将 'UnsafeMutablePointer<_>' 类型的值转换为预期的参数类型 'UnsafeMutablePointer!'”
这是我的代码
func login(portal: String, username: String, password: String) {
var loginEvent = VidyoClientInEventLogIn()
let portalCArray = UnsafeMutablePointer<Int8>(mutating: (portal as NSString).utf8String!)
withUnsafeMutablePointer(to: &loginEvent.portalUri) {
strlcpy($0, portalCArray, MemoryLayout.size(ofValue: $0))
}
}
其中 VidyoClientInEventLogIn 是:
typedef struct VidyoClientInEventLogIn_
{
/*! Portal URI, i.e. "https://example.test.com" */
char portalUri[URI_LEN];
} VidyoClientInEventLogIn;