string - 无法将类型 'GeoPoint?' 的值分配给类型 'AnyObject?' 的值

标签 string swift

您好,我可以查看此代码并已加载:

    PFGeoPoint.geoPointForCurrentLocationInBackground { (geopoint: PFGeoPoint?, error: NSError?) -> Void in

        if error == nil {

            println(geopoint)

            var user = PFUser.currentUser()


            user["location"] = geopoint


            var query = PFUser.query()
            query!.whereKey("location", nearGeoPoint:geopoint!)

            query!.limit = 10
            query!.findObjectsInBackgroundWithBlock({ (users, error) -> Void in

                var accepted = PFUser.currentUser()["accepted"] as! [String]
                var rejected = PFUser.currentUser()["rejected"] as! [String]

                for user in users {

错误是:

用户[“位置”] = 地理点

无法分配“PFGeoPoint”类型的值?为“AnyObject?”类型的值

这两行的下一个错误是相同的

var Accepted = PFUser.currentUser()["accepted"] as! [字符串] var returned = PFUser.currentUser()["rejected"] as! [字符串]

并且 AnyObject 无法转换为“[String]”

最后一个错误就行了

对于用户中的用户{

“[任何对象]?”没有名为“Generator”的成员 我希望你们能帮助我解决这些问题

最佳答案

您需要解开您的选项来访问它包含的引用(并调用它的方法)。

试试这个:

if let unwrappedUsers = users { for user in unwrappedUsers { ... } }

如果users不为空/nil/None,它的引用将被解包到unwrappedUsers

关于string - 无法将类型 'GeoPoint?' 的值分配给类型 'AnyObject?' 的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31799253/

相关文章:

电子邮件域的 Java RegEx

多个字符串的 C++ 笛卡尔积

swift - 游戏结束风格弹出 View

java - 如何计算上一个和下一个字符?

c++ - 谷歌测试 : can not create string from char array?

java - java中字符串的比较和编辑

swift - 无法在 UITextfield 上添加操作以查看 Controller

ios - 用圆角翻转 UIView

ios - 在 UITableViewCell iOS 8 (Swift) 中隐藏对象

swift - 在 swiftui 中 2 秒后推送 View