首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PFUser未展开-斯威夫特

PFUser未展开-斯威夫特
EN

Stack Overflow用户
提问于 2015-06-22 19:51:45
回答 2查看 147关注 0票数 0

我开始学习用解析快速的方法,我遇到了这样的错误:

“可选类型'PFUser?‘的值没有打开;您的意思是使用'!’还是‘’?”

我似乎不能让它起作用..。

代码语言:javascript
复制
        PFFacebookUtils.logInWithPermissions(["public_profile",
        "user_about_me", "user_birthday"], block: {
            user, error in

            if user == nil {
                println("the user canceled fb login")
                //add uialert

                return

            }
                //new user
            else if user.isNew {
                println("user singed up through FB")

                //get information from fb then save to parse
                FBRequestConnection.startWithGraphPath("/me?fields=picture,first_name,birthday,gender",  completionHandler: {
                    connection, result, error in
                    //print results
                    println(result)
                    //result dictionary about user
                    var r = result as NSDictionary
                    //prnt dictionary
                    println(NSDictionary)
                    //match parse column with what fb sends
                    user["firstName"] = r["first_name"]
                    user["gender"] = r["gender"]
                    //r = result, then key into using picture.  Then key into url using the data
                 let pictureURL = ((r["picture"] as NSDictionary)["data"] as NSDictionary) ["url"] as String
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-06-22 19:56:24

以下是解释:What is an "unwrapped value" in Swift?

代码语言:javascript
复制
PFFacebookUtils.logInWithPermissions(["public_profile",
    "user_about_me", "user_birthday"], block: {
        user, error in

        if user == nil {
            println("the user canceled fb login")
            //add uialert

            return

        }
            //new user
        else if user!.isNew {
            println("user singed up through FB")

            //get information from fb then save to parse
            FBRequestConnection.startWithGraphPath("/me?fields=picture,first_name,birthday,gender",  completionHandler: {
                connection, result, error in
                //print results
                println(result)
                //result dictionary about user
                var r = result as NSDictionary
                //prnt dictionary
                println(NSDictionary)
                //match parse column with what fb sends
                user["firstName"] = r["first_name"]
                user["gender"] = r["gender"]
                //r = result, then key into using picture.  Then key into url using the data
             let pictureURL = ((r["picture"] as NSDictionary)["data"] as NSDictionary) ["url"] as String
票数 1
EN

Stack Overflow用户

发布于 2015-06-22 19:56:04

而不是使用if user == nil {...,您应该真正使用

代码语言:javascript
复制
    if let user = user { 
       // Login succeeded...
    } 
    else { 
       // Login failed
    } 

然后,变量user将在if let中展开,您可以继续以相同的方式使用user

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30988606

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档