[英]Cannot convert value of type 'Int' to expected argument type '(inout UnsafeMutableBufferPointer<_>, inout Int) throws -> Void'
This line var machine = [CChar](_unsafeUninitializedCapacity: size, initializingWith: 0)
error throwing. 此行var machine = [CChar](_unsafeUninitializedCapacity: size, initializingWith: 0)
错误抛出。
Error Message: 错误信息:
Cannot convert value of type 'Int' to expected argument type '(inout UnsafeMutableBufferPointer<_>, inout Int) throws -> Void' 无法将'Int'类型的值转换为预期的参数类型'(inout UnsafeMutableBufferPointer <_>,inout Int)throws - > Void'
This is my Code: 这是我的代码:
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"
}
}
inout
parameters are those that are going to be modified by the function we are passing it to. inout
参数是那些将由我们传递给它的函数修改的参数。 Therefore, you need to pass it as &size
. 因此,您需要将其作为&size
传递。
I got Answer, 我得到了答案,
initializingWith: {_,_ in}
Like that: 像那样:
var machine = [CChar](_unsafeUninitializedCapacity: size, initializingWith: {_,_ in})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.