This PR proposes a refactor which improves the understandability and testability of the codebase by transitioning to an MVVM (model + view + view-model) framework, as recommended for SwiftUI. The result is increased decoupling between views and view controller.
Please note: the app hasn't completely shifted to MVVM. This PR represents an initial effort to get there.
Changes include:
Refactored MyViewController into separate files:
Model/PredictionLayer.swift: handles classifier prediction for a provided image and model.
PlayView/CameraView.swift: creates the view for the presenting video feed, acting as a coordinator for the view controller required for using AVCaptureSession.
PlayView/CaptureSessionViewController.swift: renamed file for MyViewController, but now greatly reduced in scope: it only handles the AVCaptureSession feed and relays required data via delegate to CameraView.
Refactored ContentView into separate files:
PlayView/PlayView.swift: the renamed file of ContentView, but with reduced view model logic.
PlayView/PlayViewModel.swift: the view model for PlayView. Most notably, the view model subscribes to changes on image, which then leverages PredictionLayer for inferring classifications. The result updates PredictionLabelView with the predicted label as well as confidence.
PlayView/ImagePreview.swift: logic that was moved out of ContentView into its own file. ImagePreview presents an image preview from the photo picker.
Other improvements:
Added support for landscape mode as well as orientation changes.
Minor refactor for ImagePicker.swift leveraging some SwiftUI magic.
This PR proposes a refactor which improves the understandability and testability of the codebase by transitioning to an MVVM (model + view + view-model) framework, as recommended for SwiftUI. The result is increased decoupling between views and view controller.
Changes include:
MyViewController
into separate files:Model/PredictionLayer.swift
: handles classifier prediction for a provided image and model.PlayView/CameraView.swift
: creates the view for the presenting video feed, acting as a coordinator for the view controller required for usingAVCaptureSession
.PlayView/CaptureSessionViewController.swift
: renamed file forMyViewController
, but now greatly reduced in scope: it only handles theAVCaptureSession
feed and relays required data via delegate toCameraView
.ContentView
into separate files:PlayView/PlayView.swift
: the renamed file ofContentView
, but with reduced view model logic.PlayView/PlayViewModel.swift
: the view model forPlayView
. Most notably, the view model subscribes to changes onimage
, which then leveragesPredictionLayer
for inferring classifications. The result updatesPredictionLabelView
with the predicted label as well as confidence.PlayView/ImagePreview.swift
: logic that was moved out ofContentView
into its own file.ImagePreview
presents an image preview from the photo picker.Other improvements:
ImagePicker.swift
leveraging some SwiftUI magic.Tagging #17