xcode “InfoKey”不是“UIImagePickerController”的成员类型
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/51504442/
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
'InfoKey' is not a member type of 'UIImagePickerController'
提问by Karol Idarmi
I am getting this error:
我收到此错误:
'InfoKey' is not a member type of 'UIImagePickerController'
“InfoKey”不是“UIImagePickerController”的成员类型
I had wasted time searching on the issue but failed.
我浪费了时间搜索这个问题,但失败了。
private func imagePickerController(_ picker: UIImagePickerController,
didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
picker.dismiss(animated: true, completion: nil)
guard let image = info[.originalImage] as? UIImage else {
return
}
}
Xcode 9.4, Swift 4.1
Xcode 9.4,斯威夫特 4.1
回答by rmaddy
You are attempting to use the newer iOS 12 API which requires Xcode 10. If you are using Xcode 9.4 then you are using iOS 11 and you need to use the soon to be older API.
您正在尝试使用需要 Xcode 10 的较新的 iOS 12 API。如果您使用的是 Xcode 9.4,那么您使用的是 iOS 11,您需要使用即将到来的旧 API。
private func imagePickerController(_ picker: UIImagePickerController,
didFinishPickingMediaWithInfo info: [String : Any]) {
picker.dismiss(animated: true, completion: nil)
guard let image = info[UIImagePickerControllerOriginalImage] as? UIImage else {
return
}
}
回答by zombie
First you need to remove the private
key word. it might be added to silence a warning.
首先,您需要删除private
关键字。可能会添加它以消除警告。
The syntax that you gave is from an different version of swift than 4
您提供的语法来自与 4 不同的 swift 版本
here is the new one
这是新的
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
let image = info[UIImagePickerControllerOriginalImage] as? UIImage
}