{"id":15527138,"url":"https://github.com/edonv/avcaptureviewmodel","last_synced_at":"2026-04-28T08:37:56.322Z","repository":{"id":189377691,"uuid":"680568753","full_name":"edonv/AVCaptureViewModel","owner":"edonv","description":"An ObservableObject view model for capturing photo/video on iOS for SwiftUI and UIKit.","archived":false,"fork":false,"pushed_at":"2024-03-21T15:43:16.000Z","size":630,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-06T13:19:50.688Z","etag":null,"topics":["avfoundation","camera","capture","ios","movie","observableobject","observedobject","photo","stateobject","swift","swiftui","uikit","video","viewmodel"],"latest_commit_sha":null,"homepage":"https://swiftpackageindex.com/edonv/AVCaptureViewModel","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/edonv.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"edonv"}},"created_at":"2023-08-19T17:05:44.000Z","updated_at":"2024-06-18T07:59:35.000Z","dependencies_parsed_at":"2024-12-08T12:41:45.151Z","dependency_job_id":"b787dd67-2acf-44b1-9c06-9ad5079564d2","html_url":"https://github.com/edonv/AVCaptureViewModel","commit_stats":{"total_commits":58,"total_committers":2,"mean_commits":29.0,"dds":0.03448275862068961,"last_synced_commit":"e0e6a95847b6aa9e3db221d40911a583cf635025"},"previous_names":["edonv/avcaptureviewmodel"],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edonv%2FAVCaptureViewModel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edonv%2FAVCaptureViewModel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edonv%2FAVCaptureViewModel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edonv%2FAVCaptureViewModel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/edonv","download_url":"https://codeload.github.com/edonv/AVCaptureViewModel/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246100566,"owners_count":20723479,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["avfoundation","camera","capture","ios","movie","observableobject","observedobject","photo","stateobject","swift","swiftui","uikit","video","viewmodel"],"created_at":"2024-10-02T11:04:36.859Z","updated_at":"2026-04-28T08:37:56.251Z","avatar_url":"https://github.com/edonv.png","language":"Swift","funding_links":["https://github.com/sponsors/edonv"],"categories":[],"sub_categories":[],"readme":"# AVCaptureViewModel\n\n[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fedonv%2FAVCaptureViewModel%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/edonv/AVCaptureViewModel)\n[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fedonv%2FAVCaptureViewModel%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/edonv/AVCaptureViewModel)\n\n`AVCaptureViewModel` is an `ObservableObject` with exposed `@Published` properties to be used with the provided ``CameraPreview`` (SwiftUI) or ``CameraPreviewView`` (UIKit). It allows you to build a custom interface around them as part of a larger `View` or `UIViewController` (respectively) for capturing photos and videos.\n\nIt can be used to capture photos and videos to be immediately sent to the device's photo library, or you can subscribe to provided `@Published` properties to get the captures as they happen.\n\n## Future and Next Steps\n\nThere is still more work to be done to provide more granular control, but it's already functional as it is.\n\n### Things to add:\n- [ ] Some kind of subscribable publisher (likely a `CurrentValueSubject`) for publishing events (such as photo capture starting/ending, etc)\n- [ ] Exposing more properties for customizability\n- [ ] Fix existing issues with screen rotation\n- [ ] Implement @MainActor on `AVCaptureViewModel` and implement removal of `DispatchQueue.main.async { }`\n- [ ] Figure out how to automatically resize `CameraPreviewView` to fit the size of the preview (i.e. when it's in photo mode, it doesn't fill the space)\n- [x] Add a function for pinch gesture/zoom\n\n## How to Use `AVCaptureViewModel`\n\n*COMING SOON*\n\n## Misc Notes\n- The framework doesn't currently support a built-in way to keep the screen from rotating while recording a video, as this isn't possible the way it's written. So if your app allows for multiple orientations, you'll have to listen for event changes (specifically `.movieRecordingStarted` and `.movieRecordingFinished`) and figure it out on your own. In UIKit, this is done by setting or overriding a `UIViewController`'s [`supportedInterfaceOrientations`](https://developer.apple.com/documentation/uikit/uiviewcontroller/1621435-supportedinterfaceorientations) property. There isn't currently a way to limit app rotations per view in SwiftUI. \n\n## Credit\n\nMost of the behind-scenes-code stems directly from Apple's [AVCam tutorial](https://developer.apple.com/documentation/avfoundation/capture_setup/avcam_building_a_camera_app). I started with the current version of it (parts of which require iOS 17/Xcode 15), and I made it backwards-compatible to iOS 13. I also reworked parts of the code to work with properties of `AVCaptureViewModel`, as well as to replace `@IBAction`s and `@IBOutlets`. Additionally, I turned their `PreviewView` into `CameraPreviewView` and wrapped it with `CameraPreview`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fedonv%2Favcaptureviewmodel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fedonv%2Favcaptureviewmodel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fedonv%2Favcaptureviewmodel/lists"}