此行var machine = [CChar](_unsafeUninitializedCapacity: size, initializingWith: 0)
抛出错误。
错误消息:
无法将类型'Int'的值转换为预期的参数类型'(inout UnsafeMutableBufferPointer <_>,inout Int)throws-> Void'
这是我的代码:
struct MailTemplate {
let destination = "test@gmail.com"
let subject = "Test"
let body:String
init(){
let appVersion: String! = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String
var platform: String {
var size: Int = 0
sysctlbyname("hw.machine", nil, &size, nil, 0)
var machine = [CChar](_unsafeUninitializedCapacity: size, initializingWith: 0)
sysctlbyname("hw.machine", &machine, &size, nil, 0)
return String.fromCString(machine)!
}
body = "Email Body"
}
}
答案 0 :(得分:0)
inout
参数是将要由我们传递给它的函数修改的参数。因此,您需要将其作为&size
传递。
答案 1 :(得分:0)
我得到了答案
initializingWith: {_,_ in}
喜欢:
var machine = [CChar](_unsafeUninitializedCapacity: size, initializingWith: {_,_ in})