employee
。因此,您可以在completion
的checkCreateTabPermission
中调用所需的方法:我如何在完成区之外访问员工价值,以便在ViewController
中的任何位置使用它?>
extension TabsParentViewController{
class func checkCreateTabPermission(completion: @escaping PermCompletionWithCancel){
RRS.s.permissionService.checkForPermission(.createTab, completion: { (pass, employee, cancel) in
if !cancel {
ActivityLogsBuilder.logActivity(forEmployee: employee, module: .tabs, action: ActivityLogsBuilder.action(from: LogAction.createTab, authorized: pass))
}
completion(pass, employee, cancel)
})
}
}
我如何在完成块之外访问雇员值,以便在ViewController扩展TabsParentViewController {类func checkCreateTabPermission(...]
checkCreateTabPermission
称为:checkCreateTabPermission { pass, employee, cancel in
// here you can use the `employee`
}
employee
。因此,您可以在completion
的checkCreateTabPermission
中调用所需的方法:checkCreateTabPermission { pass, employee, cancel in
myMethod(employee: employee)
}
或者如果要访问completion
以外的员工,则可以在返回值后声明一个变量(默认为nil
)以保存其值:
var myEmployee: Employee?
checkCreateTabPermission { [weak self] pass, employee, cancel in
self?.myEmployee = employee
}
// you could use `myEmployee` here, but you have to make sure its not nil,
// in other words, `checkCreateTabPermission` has been called and retrieved one.
if let myUnwrappedEmployee = myEmployee {
// use `myUnwrappedEmployee`...
}
employee
。因此,您可以在completion
的checkCreateTabPermission
中调用所需的方法: