简体   繁体   English

无法将'Int'类型的值转换为预期的参数类型'(inout UnsafeMutableBufferPointer <_>,inout Int)throws - > Void'

[英]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.

相关问题 无法转换&#39;UILabel!&#39;类型的值! 预期参数&#39;type inout String&#39; - cannot convert value of type 'UILabel!' to expected argument 'type inout String' swift无法将类型“ [Liquor]”的值转换为预期的参数类型“ inout _” - swift Cannot convert value of type '[Liquor]' to expected argument type 'inout _' 无法转换“inout NSNumber”类型的值? 到预期的参数类型 &#39;AutoreleasingUnsafeMutablePointer<AnyObject?> &#39; 错误 - Cannot convert value of type 'inout NSNumber?' to expected argument type 'AutoreleasingUnsafeMutablePointer<AnyObject?>' error 无法将&#39;(Int) - &gt; Void&#39;类型的值转换为预期的参数类型&#39;(Any) - &gt; Void&#39; - Cannot convert value of type '(Int) -> Void' to expected argument type '(Any) -> Void' 无法将类型 &#39;(_) throws -&gt; ()&#39; 的值转换为预期的参数类型 &#39;((UIAlertAction) -&gt; Void)?&#39; - Cannot convert value of type '(_) throws -> ()' to expected argument type '((UIAlertAction) -> Void)?' 无法使用类型为&#39;(inout inout $ T6,inout inout $ T11)的参数列表调用&#39;subscript&#39; - Cannot invoke 'subscript' with an argument list of type '(inout inout $T6, inout inout$T11) 无法将 Int 类型的值转换为预期的参数类型“...” - Cannot convert value of type Int to expected Argument type '...' 无法将Int类型的值转换为预期的参数类型Bool - Cannot convert value of type Int to expected argument type Bool &#39;无法将&#39;Int&#39;类型的值转换为预期的参数类型&#39;CGPoint&#39; - 'Cannot convert value of type 'Int' to expected argument type 'CGPoint' 无法在Swift 3中将字符串类型的值转换为预期的参数类型int - cannot convert value of type string to expected argument type int in swift 3
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM