- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我正在使用 Apple's Swift iOS Tutorial .这是抛出错误,
Cannot subscript a value of type '[String : Any]' with an index of type 'UIImagePickerController.InfoKey'
他们定义的函数如下。
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
// The info dictionary may contain multiple representations of the image. You want to use the original.
guard let selectedImage = info[UIImagePickerControllerOriginalImage] as? UIImage else {
fatalError("Expected a dictionary containing an image, but was provided the following: \(info)")
}
// Set photoImageView to display the selected image.
photoImageView.image = selectedImage
// Dismiss the picker.
dismiss(animated: true, completion: nil)
}
我使用的是 Xcode 版本 10.0 beta 3,其中包括 Swift 4.2。
我想了解如何遍历文档以了解可能已更改或损坏的内容。
最佳答案
方法的签名在 Swift 4.2 中发生了变化
func imagePickerController(_ picker: UIImagePickerController,
didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any])
你必须写
guard let selectedImage = info[.originalImage] as? UIImage else {
fatalError("Expected a dictionary containing an image, but was provided the following: \(info)")
}
您可以通过阅读 documentation 自行了解此类术语更改。或者通过注释掉整个方法,重新键入前几个字符并使用代码完成。
关于ios - 无法使用类型为 '[String : Any]' 的索引下标类型为 'UIImagePickerController.InfoKey' 的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51342028/
我的以下代码在 swift 4 上运行良好,但在升级到 swift 4.2 后出现此错误,我浪费了 3 个小时搜索问题所在但失败了。如果有人能指导我如何解决这个问题,请多多指教。 func image
我收到这个错误: 'InfoKey' is not a member type of 'UIImagePickerController' 我浪费了时间搜索这个问题但失败了。 private func
我有一个选择器,在成功选择视频后,我无法获得 Assets 的路径。所以我有这个: func imagePickerController(_ picker: UIImagePickerControll
我想弄清楚如何更新我的代码以支持 UIImagePickerController() 在 Swift 5 中工作的新方式 我能够在此处的代码的另一部分修复相同的错误: func imagePi
我正在使用 Apple's Swift iOS Tutorial .这是抛出错误, Cannot subscript a value of type '[String : Any]' with an
这个问题在这里已经有了答案: Cannot subscript a value of type '[String : Any]' with an index of type 'UIImagePick
我是一名优秀的程序员,十分优秀!