我收到此错误:
“ InfoKey”不是“ UIImagePickerController”的成员类型
我浪费了时间在问题上,但失败了。
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
答案 0 :(得分:6)
您正在尝试使用需要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
}
}
答案 1 :(得分:1)
首先,您需要删除private
关键字。可以添加它以使警告静音。
您提供的语法来自不同于4的swift版本
这是新的
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
let image = info[UIImagePickerControllerOriginalImage] as? UIImage
}