【发布时间】:2018-12-22 19:59:11
【问题描述】:
我正在使用Apple's Swift iOS Tutorial。这是抛出一个错误,
不能使用“UIImagePickerController.InfoKey”类型的索引为“[String : Any]”类型的值下标
他们定义的函数如下。
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。
我想了解如何遍历文档以了解可能已更改或损坏的内容。
【问题讨论】:
-
我注意到本教程后面的另一行也抛出了一个错误 -
button.addTarget(self, action: #selector(RatingControl.ratingButtonTapped(button:)), for: .touchUpInside)。如果其他人有同样的问题——我可以通过在课程行的开头添加@objcMembers来解决它,就像这样:@objcMembers class RatingControl: UIStackView {。见hackingwithswift.com/example-code/language/…
标签: ios swift uiimagepickercontroller