LoginSignup
1
0

More than 3 years have passed since last update.

Apple developer documentにおけるバージョン違いのエラー

Last updated at Posted at 2021-03-07

初めまして、R_tattsu2060です。
会社員(事務職)と一児の父をしながら隙間時間でswiftを独学しています。

今回初めてのQiita投稿になります。

Apple developer documentで「FoodTracker」というサンプルアプリのチュートリアルを実行しているとバージョンの違いからエラー表示が出ました。

Start Developing iOS Apps (Swift)(2016)

「UIビューを操作する」imagePickerControllerのコードより抜粋。

2016年版

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {

    guard let selectedImage = info[UIImagePickerControllerOriginalImage] as? 
    UIImage else {
        fatalError("Expected a dictionary containing an image, but was provided the following: \(info)")
    }
}

これを以下のように修正するとビルドできるようになります。

2021年版

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {

        guard let selectedImage = info[UIImagePickerController.InfoKey.originalImage] as?
        UIImage else {
            fatalError("Expected a dictionary containing an image, but was provided the following: \(info)")
}

シュミレーターでImageView画面をタップしても何も反応がない場合は、
inspector - [interaction]Usre Interaction Enabledにチェックを入れると解決します。

ちなみに同じことで悩んでいた方が相談していたサイトがあったので追記しておきます。
Apple Tutorial Bug
※英語サイトです

以上です。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0