gpt4 book ai didi

ios - 无法使用类型为 '[String : Any]' 的参数下标类型为 'UIImagePickerController.InfoKey' 的值

转载 作者:行者123 更新时间:2023-11-29 11:26:17 25 4
gpt4 key购买 nike

我想弄清楚如何更新我的代码以支持 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com