错误:'表达式的类型是不明确的,没有更多的上下文' [英] Error: 'Type of expression is ambiguous without more context'

查看:921
本文介绍了错误:'表达式的类型是不明确的,没有更多的上下文'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很新的编码Swift,所以请原谅我,如果这个错误是一个简单的答案!

I'm pretty new to coding Swift, so please excuse me if this error is a simple answer!

我会收到一条错误消息,表示没有更多上下文的表达式类型是不明确的。

I keep getting an error message that says "Type of expression is ambiguous without more context."

    var findTimelineData: PFQuery = PFQuery(className: "Sweets")
    findTimelineData.findObjectsInBackgroundWithBlock {
        (objects:[AnyObject]?, error:NSError?) -> Void in

        if error == nil {
            for object:PFObject in objects! { // ----This is the error line---
                self.timelineData.addObject(object)
            }
        }
    }

我明白问题是什么,我只是不知道如何去修复它。我已经看到关于这个回答的其他问题,但没有一个关于迭代AnyObject数组。

I understand what the problem is, I'm just not certain how to go about fixing it. I've seen other questions about this answered, but none about iterating through an array of AnyObject.

谢谢!

推荐答案

您可以帮助编译器知道对象是这样的:

You can help the compiler know what objects is like this:

for object in objects as! [PFObject] {
    self.timelineData.addObject(object)
}

这篇关于错误:'表达式的类型是不明确的,没有更多的上下文'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆