{"id":20478120,"url":"https://github.com/swiftui-plus/media","last_synced_at":"2025-04-13T13:13:09.438Z","repository":{"id":116152801,"uuid":"400813186","full_name":"SwiftUI-Plus/Media","owner":"SwiftUI-Plus","description":"A SwiftUI dynamic property wrapper for fetching media from your photo library. (iOS, tvOS, macOS)","archived":false,"fork":false,"pushed_at":"2021-09-22T10:23:40.000Z","size":17,"stargazers_count":33,"open_issues_count":0,"forks_count":6,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-27T04:12:34.135Z","etag":null,"topics":["ios","macos","medialibrary","photolibrary-ios","photopicker","swift","swiftui","tvos"],"latest_commit_sha":null,"homepage":"https://benkau.com/packages.json","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/SwiftUI-Plus.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"License.md","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":"shaps80","custom":"paypal.me/shapsuk"}},"created_at":"2021-08-28T14:30:20.000Z","updated_at":"2025-02-12T01:39:34.000Z","dependencies_parsed_at":null,"dependency_job_id":"37e0225f-ed63-445c-95c3-bddceab53f8e","html_url":"https://github.com/SwiftUI-Plus/Media","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SwiftUI-Plus%2FMedia","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SwiftUI-Plus%2FMedia/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SwiftUI-Plus%2FMedia/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SwiftUI-Plus%2FMedia/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SwiftUI-Plus","download_url":"https://codeload.github.com/SwiftUI-Plus/Media/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248717237,"owners_count":21150389,"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":["ios","macos","medialibrary","photolibrary-ios","photopicker","swift","swiftui","tvos"],"created_at":"2024-11-15T15:35:15.868Z","updated_at":"2025-04-13T13:13:09.432Z","avatar_url":"https://github.com/SwiftUI-Plus.png","language":"Swift","funding_links":["https://github.com/sponsors/shaps80","paypal.me/shapsuk"],"categories":[],"sub_categories":[],"readme":"![ios](https://img.shields.io/badge/iOS-13-green)\n![tv](https://img.shields.io/badge/tvOS-13-green)\n![mac](https://img.shields.io/badge/macOS-10.15-green)\n\n# Media\n\n\u003e Also available as a part of my [SwiftUI+ Collection](https://benkau.com/packages.json) – just add it to Xcode 13+\n\nA package for simplifying the user of the camera and the user's photo library in SwiftUI.\n\n## Features\n\n-   Dynamic property wrappers for fetching media from the photo library\n-   Camera modifier for easily taking a photo\n-   ImagePicker modifier for allowing the user to pick a photo from their library\n\n\u003e Note: Permission requests and Info.plist values are not handled by this framework. You should use the standard UI to perform these actions as usual.\n\n## Example\n\nFetch all asset collections of a given type and subtype:\n\n```swift\n// Its not necessary to `import Photos` as the framework does this for you.\nimport Media\n\nstruct AlbumsView: View {\n\n    @FetchAssetCollection(album: .album, kind: .albumRegular)\n    private var albums\n\n    var body: some View {\n        List(albums) { album in\n            Text(album.localizedTitle ?? \"\")\n        }\n    }\n\n}\n```\n\nFor camera or image picker implementations:\n\n```swift\n@State private var takePhoto: Bool = false\n@State private var chooseFromLibrary: Bool = false\n\nvar body: some View {\n    VStack(spacing: 20) {\n        Button {\n            takePhoto = true\n        } label: {\n            Text(\"Take a photo\")\n        }\n        .camera(isPresented: $takePhoto) { result in\n            print(try! result.get())\n        }\n\n        Button {\n            chooseFromLibrary = true\n        } label: {\n            Text(\"Choose from Library\")\n        }\n        .imagePicker(isPresented: $chooseFromLibrary) { result in\n            print(try! result.get())\n        }\n    }\n}\n```\n\n## Inspiration\n\nThe property wrapper has heavily inspired by the new `FetchRequest` provided by SwiftUI. As such, it conforms to `RandomAccessCollection` allowing it to be used in all the same places, e.g. `List`, `ForEach`, etc...\n\nThis greatly simplifies the use of the photos framework library when integrating into a SwiftUI package.\n\nSince the library is also a `dynamic` property, updates occuring in the users library are automatically tracked and reflecting in your SwiftUI views.\n\n## Custom Queries\n\nThe property wrapper initializers provide various overrides to ensure you can customize the queries you need to perform.\n\nIn cases where a convenience initializer hasn't been provided, you can simply pass your own `PHFetchOptions` instance:\n\n```swift\nprivate static var options: PHFetchOptions = {\n    let options = PHFetchOptions()\n    options.predicate = ...\n    return options\n}()\n\n@FetchAssetCollection(options)\nprivate var custom\n```\n\n## Supports API\n\n`PHAssetCollection`\n\n```swift\n@FetchAssetCollection(\n    album: .smartAlbum,\n    filter: NSPredicate(\n        format: \"NOT (assetCollectionSubtype IN %@)\",\n        [\n            PHAssetCollectionSubtype.smartAlbumUserLibrary.rawValue,\n            PHAssetCollectionSubtype.smartAlbumAllHidden.rawValue,\n            PHAssetCollectionSubtype.smartAlbumFavorites.rawValue,\n        ]\n    )\n) var albums\n```\n\n`PHCollectionList`\n\n```swift\n@FetchCollectionList(\n    list: .smartFolder,\n    kind: .any\n) private var folders\n```\n\n`PHAsset`\n\n```swift\n// You can instantiate your results during init:\n@FetchAssetList\nprivate var assets: MediaResults\u003cPHAsset\u003e\n\n// Or, if you already have a set of results from a `PHFetchResult\u003cPHAsset\u003e` instance:\n@FetchAssetList(results)\nprivate var assets\n\n// Alternatively, if you have a `PHAssetCollection` instance:\n@FetchAssetList(in: collection)\nprivate var assets\n```\n\nThere are multiple overrides for all of the above to allow for most customizations, alternatively you can pass a `PHFetchOptions` instance yourself as mentioned above.\n\n## Exclusions\n\nThe primary purpose of this library is to simplify the usage of the `Photos` framework in SwiftUI applications. As such, permission requests and mutations are not included.\n\nThose APIs are not an issue that needs fixing by this library.\n\nInstead you should continue to use the existing APIs available via the `Photos` framework. Since the use of `Photos` types is required, the library automatically imports `Photos` for you so adding an additional import is redundant.\n\n## Installation\n\nThe code is packaged as a framework. You can install manually (by copying the files in the `Sources` directory) or using Swift Package Manager (**preferred**)\n\nTo install using Swift Package Manager, add this to the `dependencies` section of your `Package.swift` file:\n\n`.package(url: \"https://github.com/SwiftUI-Plus/Media.git\", .upToNextMinor(from: \"1.0.0\"))`\n\n\u003e Note: The package requires iOS v13+\n\n## Other Packages\n\nIf you want easy access to this and more packages, add the following collection to your Xcode 13+ configuration:\n\n`https://benkau.com/packages.json`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fswiftui-plus%2Fmedia","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fswiftui-plus%2Fmedia","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fswiftui-plus%2Fmedia/lists"}