我正在尝试集成人脸/触摸 ID 登录,但我在苹果文档[unowned self]
中看到了一个闭包。那是什么,有什么好处?示例代码:
let context = LAContext()
var error: NSError?
if context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &error) {
let reason = "Identify yourself!"
context.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, localizedReason: reason) {
[unowned self] (success, authenticationError) in
DispatchQueue.main.async {
if success {
print("Authenticated!")
} else {
// error
}
}
}
} else {
// no biometry
}