Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/106.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 无法为类型为';[字符串:任意]';带有类型为';UIImagePickerController.InfoKey';_Ios_Xcode11_Swift5 - Fatal编程技术网

Ios 无法为类型为';[字符串:任意]';带有类型为';UIImagePickerController.InfoKey';

Ios 无法为类型为';[字符串:任意]';带有类型为';UIImagePickerController.InfoKey';,ios,xcode11,swift5,Ios,Xcode11,Swift5,我正在尝试如何更新代码,以支持UIImagePickerController()在Swift 5中的新工作方式 我在这里的另一段代码中修复了相同的错误: func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey: Any]) { guard let image = inf

我正在尝试如何更新代码,以支持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
现在是一个带有大小写
.originalImage
的枚举。如果你想用一个字符串为老式的方法下标,只需输入原始值:
UIImagePickerController.InfoKey.originalImage.rawValue

 $0[UIImagePickerController.InfoKey.originalImage.rawValue] as! UIImage