- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想弄清楚如何更新我的代码以支持 UIImagePickerController() 在 Swift 5 中工作的新方式
我能够在此处的代码的另一部分修复相同的错误:
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey: Any]) {
guard let image = info[.originalImage] as? UIImage else { return }
let sellLandingVC = navigationController.topViewController as? SellLandingViewController
sellLandingVC?.viewModel.insertSelectedImage(image)
navigationController.dismiss(animated: true, completion: nil)
}
这是我的代码,在调用 imagePicker.rx.didFinishPickingMediaWithInfo.map
时出现错误private func setupRx() {
let imagePicker = UIImagePickerController()
Observable.combineLatest(checkIfPermissionIsGranted(), captureButton.rx.tap) { (isGranted, _ ) in return isGranted }
.observeOn(MainScheduler.instance)
.subscribe(onNext: { [weak self] isGranted in
self?.captureButton.pulsate()
if !isGranted {
self?.displayAlert(with: self?.viewModel.accessDeniedTitle, message: self?.viewModel.accessDeniedMessage, actions: [UIAlertAction.cancel(), UIAlertAction.settings()])
} else {
imagePicker.sourceType = .photoLibrary
imagePicker.allowsEditing = false
self?.present(imagePicker, animated: true)
}
})
.disposed(by: disposeBag)
imagePicker.rx.didFinishPickingMediaWithInfo
.map {
$0[UIImagePickerController.InfoKey.originalImage] as! UIImage
//This is where I'm getting the error
}
.map {
ProfilePictureCommand.setImage($0)
}
.bind(to: viewModel.concurrentCommandSubject)
.disposed(by: disposeBag)
viewModel.stateObservable
.map {
$0.userImage ?? #imageLiteral(resourceName: "email-signup-avatar")
}
.bind(to: profileImageView.rx.image)
.disposed(by: disposeBag)
imagePicker.rx.didFinishPickingMediaWithInfo
.subscribe(onNext: { _ in
imagePicker.dismiss(animated: true)
})
.disposed(by: disposeBag)
viewModel.stateObservable
.map {
return $0.isContinueEnabled
}
.bind(to: continueButton.rx.isEnabled)
.disposed(by: disposeBag)
viewModel.stateObservable
.map {
return $0.isContinueEnabled
}
.map {
$0 ? UIColor.colorHex303030(alpha: 1.0) : UIColor.colorHexC5C5C5(alpha: 1.0)
}
.bind(to: continueButton.rx.scBackgroundColor)
.disposed(by: disposeBag)
continueButton.rx.tap
.map { ProfilePictureCommand.next }
.bind(to: viewModel.concurrentThrottleCommandSubject)
.disposed(by: disposeBag)
}
最佳答案
您的 rx 版本为您提供了 [String:Any]
而不是 [UIImagePickerController.InfoKey: Any]
。 UIImagePickerController.InfoKey
现在是一个带有 case .originalImage
的枚举。如果您想使用字符串以老式方式下标,只需询问原始值:UIImagePickerController.InfoKey.originalImage.rawValue
$0[UIImagePickerController.InfoKey.originalImage.rawValue] as! UIImage
关于ios - 无法使用类型为 '[String : Any]' 的参数下标类型为 'UIImagePickerController.InfoKey' 的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58531806/
我的以下代码在 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
我是一名优秀的程序员,十分优秀!