ios - 不清楚 "Type of expression is ambiguous without more context"错误

标签 ios swift

几个月后我回到了我的旧 XCode 项目,现在我遇到了很多以前没有的错误,我认为这与更新的语法有关。

为什么我会看到:

Type of expression is ambiguous without more context

对于这个 block

@IBAction func submitUrl(sender: UIButton) {
    var app = UIApplication.sharedApplication().delegate as! AppDelegate
    //Error occurs in below declaration of studentDict
    var studentDict = ["latitude": self.latitude, "longitude": self.longitude, "firstName": app.firstName, "lastName": app.lastName, "mediaURL": urlField.text]
    var studentInfo = StudentInformation(data: studentDict as! [String : AnyObject])
    ParseClient.sharedInstance().postStudent(studentInfo, mapString: self.mapString){(success,data) in
        if(success){
            self.dismissViewControllerAnimated(true, completion: nil)
        }
        else{
            Shared.showError(self,errorString: data["ErrorString"] as! String)
        }

    }
}

我尝试了 studentDict:NSArraystudentDict:Dictionary 因为我认为它无法正确解释 studentDict 中的内容,但是那没有帮助。到底是什么错误告诉我我失踪了?

最佳答案

您初始化时使用的一个或多个值可能是可选的,因此可以为零。这就是您收到此错误的原因

var studentDict:[String:AnyObject?] = ["latitude": self.latitude, "longitude": self.longitude, "firstName": app.firstName, "lastName": app.lastName, "mediaURL": urlField.text]

关于ios - 不清楚 "Type of expression is ambiguous without more context"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33158125/

相关文章:

ios - 如果 tableview 为空,则显示标签和图像

ios - 通过kvo观察realm List类型时如何获取 "old"值

objective-c - 无法以编程方式在 Xcode 4.2 中设置标签栏图像

ios - 如何制作具有1周试用期的iDevice应用,然后需要用户付费?

iphone - 如何在UIView中处理背景图片方向

ios - JSON 模型 - 如果使用方法 "arrayOfModelsFromDictionaries",请不要将所有对象添加到数组中

ios - Action Extension,在 Instant Markup 中获取图像返回空白屏幕

swift - 在 SceneKit 中的平面上重复纹理

iphone - iCloud 和 GEOResourceManifestServerRemoteProxy : Lost connection to geod warning

string - 如何快速从字符串中删除一些特定的 HTML 标签?