Saturday, July 16, 2022

[FIXED] How to unwrap an callback in swift?

Issue

I'm using FB Login for my app in Swift and when I make a graph request, it returns the following result:

Optional({
    email = "arjun.ramjams@gmail.com";
    id = 10218497873670001;
    name = "Arjun Ram";
})

Now, how should I read, each individual value(i.e: email, id and name)?


Solution

func fetchProfile() {
        let parameters = ["fields": "id,email, first_name, last_name"]
        GraphRequest(graphPath: "me",parameters: parameters).start{(connection, user, Err) in
            if Err != nil {
                print(Err!)
                return

            }
            let dic = user as! NSDictionary
            let userID = dic["id"] as! String
            let Email = dic["email"] as! String
            let fname = dic["first_name"] as! String
            let lname = dic["last_name"] as! String

        }

}


Answered By - Shubhendu Devmurari
Answer Checked By - Mildred Charles (PHPFixing Admin)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.