簡體   English   中英

無法將類型“ Int”的值轉換為預期的參數類型“ UnsafeMutablePointer <Int32> !

[英]Cannot convert value of type 'Int' to expected argument type 'UnsafeMutablePointer<Int32>!'

通過使用此答案,我在swift 4.1中遇到此錯誤,即Cannot convert value of type 'Int' to expected argument type 'UnsafeMutablePointer<Int32>!'

var notify_token: Int
notify_register_dispatch("com.apple.springboard.lockstate", notify_token, DispatchQueue.main, { (_ token: Int) -> Void in 
    var state: UInt64 = UINT64_MAX
    notify_get_state(token, state)
    if state == 0 {
        print("unlock device")
    }
    else {
        print("lock device")
    }

如何解決呢?

在此處輸入圖片說明

嘗試這樣的事情:

var notify_token: Int32

notify_register_dispatch("com.apple.springboard.lockstate", &notify_token, DispatchQueue.main, { (_ token: Int) -> Void in
    var state: UInt64 = UINT64_MAX
    notify_get_state(token, state)
    if state == 0 {
        print("unlock device")
    }
    else {
        print("lock device")
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM