无法指定“GeoPoint”类型的值?到'AnyObject?'类型值的值

时间:2015-08-04 01:26:12

标签: 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 {

错误是:

user [“location”] = geopoint

无法指定“PFGeoPoint”类型的值?到“AnyObject?”类型的值

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

var accepted = PFUser.currentUser()[“accepted”]为! [串]                     var rejected = PFUser.currentUser()[“rejected”] as! [字符串]

并且AnyObject不能转换为'[String]'

,最后一个错误就行了

用户{

中的用户

'[AnyObject]?没有名为'Generator'的成员 我希望你们可以帮助我们

1 个答案:

答案 0 :(得分:1)

您需要解包您的可选项以访问它包含的引用(并在其上调用方法)。

试试这个:

- (void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

Iff if let unwrappedUsers = users { for user in unwrappedUsers { ... } } 不为空/ users / nil,其引用将被解包到None

相关问题