我有一个应用程序,其中有2个角色," admin"和"员工"。在注册时,我将segue设置到注册按钮,它会自动为员工或管理员视图控制器执行正确的segue。但是在创建并注销用户并尝试重新登录之后,我如何设置条件if else语句来查询当前用户的角色并相应地执行正确的segue。提前致谢。这是我在初始视图控制器/登录屏幕上的代码。
override func viewDidAppear(animated: Bool) {
//need to query current users role...and then if else, and segue to either Admin Home or Employee Home
var roleQueryClass = PFQuery(className: "_Role")
var roleQuery = PFRole.query()
roleQuery?.whereKey("name", equalTo: "Admin")
roleQuery?.findObjectsInBackgroundWithBlock({ (objects, error) -> Void in
if let role = objects {
for object in role {
if let role = object as? PFRole {
if PFRole() == PFUser.currentUser() {
self.performSegueWithIdentifier("toHomeFromSignUp", sender: self)
} else {
self.performSegueWithIdentifier("toEmployeeHome", sender: self)
答案 0 :(得分:0)
在注册时将角色保存在NSUserDefaults中,并在登录时检查NSUserDefaults中的值,并相应地进行segue。