Я пытаюсь понять, как обновить мой код для поддержки нового способа работы 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)
}