ios 错误:“没有更多上下文,表达式类型不明确”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31211809/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 06:43:10  来源:igfitidea点击:

Error: 'Type of expression is ambiguous without more context'

iosswiftparse-platformcompiler-errors

提问by Kody R.

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

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

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)
            }
        }
    }

Any suggestions?

有什么建议?

Thanks!

谢谢!

回答by Eric Aya

You can help the compiler know what objectsis like this:

你可以帮助编译器知道objects是这样的:

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

回答by Tom Howard

if let pfObjects = objects as? [PFObject]
{
    for pfObject in pfObjects
    {
        self.timelineData.addObject(pfObject)
    }
}

...exclamation points in Swift code give me the heeby jeebies.

... Swift 代码中的感叹号给了我heeby jeebies。

回答by Zigii Wong

If you are writing some code likes:

如果您正在编写一些代码,例如:

for (i, view) in views { 
}

You need to add enumerated:

您需要添加enumerated

for (i, view) in views.enumerated() {
}

And now it should work.

现在它应该可以工作了。