无法转换类型&#39; Int&#39;预期的参数类型&#39; UnsafeMutablePointer <int32>!&#39;

时间:2018-05-03 08:45:16

标签: ios swift darwin

使用此Answer我在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")
    }

如何解决这个问题?

enter image description here

1 个答案:

答案 0 :(得分:1)

尝试这样的事情:

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")
    }
}