見出し画像

アウトプット ーAPI編ー

今日は以下のYouTubeの動画でやっていることをAPI取得、リファクタリングの練習をかねてMVVM形式に変更して作成してみました。なお、ストーリボードは使用していません。

このくらいの短いコードであれば必要ないかもしれないですが練習のためですw

また、動画では使っていなかったのですがURL画像を読み込むためにSDWebImageも活用しています!


まずはストリーボードを使わないのでsceneDelegate.swiftにて以下のように変更します。

    func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
       // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
       // If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
       // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
       guard let scene = (scene as? UIWindowScene) else { return }
       window = UIWindow(windowScene: scene)
       window?.rootViewController = UINavigationController(rootViewController: ViewController())
   }

次にUIの設定を行います。

スクリーンショット 2021-05-19 6.20.27

次にAPI処理を実装していきます。

スクリーンショット 2021-05-19 7.05.06

できました!

以下がコードになります!


この記事が気に入ったらサポートをしてみませんか?