{"id":18421463,"url":"https://github.com/rebeloper/imagepickerview","last_synced_at":"2025-04-07T14:31:50.729Z","repository":{"id":169311158,"uuid":"329321547","full_name":"rebeloper/ImagePickerView","owner":"rebeloper","description":"🌇 PHPickerViewController / UIImagePickerController for SwiftUI","archived":false,"fork":false,"pushed_at":"2022-12-01T04:47:45.000Z","size":36,"stargazers_count":38,"open_issues_count":1,"forks_count":6,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-22T19:43:45.386Z","etag":null,"topics":["imagepicker","imagepickerview","imagepickerview-swiftui","phpickerviewcontroller","swiftui","uiimagepickercontroller","uiimagepickercontroller-swiftui"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rebeloper.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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}},"created_at":"2021-01-13T13:46:43.000Z","updated_at":"2024-12-22T17:30:18.000Z","dependencies_parsed_at":null,"dependency_job_id":"99146fce-6736-4a6d-b8f8-f8115f0bd55a","html_url":"https://github.com/rebeloper/ImagePickerView","commit_stats":null,"previous_names":["rebeloper/imagepickerview"],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rebeloper%2FImagePickerView","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rebeloper%2FImagePickerView/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rebeloper%2FImagePickerView/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rebeloper%2FImagePickerView/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rebeloper","download_url":"https://codeload.github.com/rebeloper/ImagePickerView/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247669932,"owners_count":20976480,"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":["imagepicker","imagepickerview","imagepickerview-swiftui","phpickerviewcontroller","swiftui","uiimagepickercontroller","uiimagepickercontroller-swiftui"],"created_at":"2024-11-06T04:25:45.778Z","updated_at":"2025-04-07T14:31:50.723Z","avatar_url":"https://github.com/rebeloper.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🌇 ImagePickerView\n\n![swift v5.3](https://img.shields.io/badge/swift-v5.3-orange.svg)\n![platform iOS](https://img.shields.io/badge/platform-iOS-blue.svg)\n![deployment target iOS 14](https://img.shields.io/badge/deployment%20target-iOS%2014-blueviolet)\n\n**ImagePickerView** is a lightweight library which brings `PHPickerViewController` / `UIImagePickerController` to `SwiftUI`.\n\n## 💻 Installation\n### 📦 Swift Package Manager\nUsing \u003ca href=\"https://swift.org/package-manager/\" rel=\"nofollow\"\u003eSwift Package Manager\u003c/a\u003e, add it as a Swift Package in Xcode 11.0 or later, `select File \u003e Swift Packages \u003e Add Package Dependency...` and add the repository URL:\n```\nhttps://github.com/rebeloper/ImagePickerView.git\n```\n### ✊ Manual Installation\nDownload and include the `ImagePickerView` folder and files in your codebase.\n\n### 📲 Requirements\n- iOS 14+\n- Swift 5.3+\n\n## 👉 Import\n\nImport `ImagePickerView` into your `View`\n\n```\nimport ImagePickerView\n```\n\n## 🧳 Features\n\nHere's the list of the awesome features `ImagePickerView` has:\n- [X] use `PHPickerViewController` as a `View` in `SwiftUI` projects (recommended, introduced in `iOS14`)\n- [X] use `UIImagePickerController` as a `View` in `SwiftUI` projects (not-recommended; use only for single image picking and when you want to enable editing) \n- [X] set `filter` and `selectionLimit` in `ImagePickerView`\n- [X] `didCancel`, `didSelect` and `didFail` delegate callbacks for `ImagePickerView`\n- [X] set `allowsEditing` in `UIImagePickerView`\n- [X] `didCancel` and `didSelect` delegate callbacks for `UIImagePickerView`\n\n## 💻 How to Use\n\nSelecting images from our iPhone library is needed when changing a profile picture, posting an update, or sharing the photo of your pet. In `UIKit` `Pre-iOS14` we would use `UIImagePickerController`, but as of `iOS14` Apple introduced `PHPickerViewController`. \n`ImagePickerView` supports both of them:\n`UIImagePickerController` -\u003e `UIImagePickerView`\n`PHPickerViewController` -\u003e `ImagePickerView`\n\nJust check out these examples where the `UIImagePickerView`/`ImagePickerView` is presented upon a tap of a `Button`. \n\n## `UIImagePickerView`\n\n```\nimport SwiftUI\nimport ImagePickerView\n\nstruct UIImagePickerControllerContentView: View {\n    \n    @State var isImagePickerViewPresented = false\n    @State var pickedImage: UIImage? = nil\n    \n    var body: some View {\n        VStack(spacing: 12) {\n            Text(\"UIImagePickerView\").font(.largeTitle)\n            \n            Button {\n                isImagePickerViewPresented = true\n            } label: {\n                VStack {\n                    if pickedImage == nil {\n                        Image(systemName: \"camera\")\n                            .font(.largeTitle)\n                    } else {\n                        Image(uiImage: pickedImage!)\n                            .resizable()\n                            .frame(width: 66, height: 66)\n                            .cornerRadius(33)\n                    }\n                }\n            }\n            .sheet(isPresented: $isImagePickerViewPresented) {\n                UIImagePickerView(allowsEditing: true, delegate: UIImagePickerView.Delegate(isPresented: $isImagePickerViewPresented, didCancel: { (uiImagePickerController) in\n                    print(\"Did Cancel: \\(uiImagePickerController)\")\n                }, didSelect: { (result) in\n                    let uiImagePickerController = result.picker\n                    let image = result.image\n                    print(\"Did Select image: \\(image) from \\(uiImagePickerController)\")\n                    pickedImage = image\n                }))\n            }\n            \n            Spacer()\n        }\n    }\n}\n```\n\n## `ImagePickerView`\n\n```\nimport SwiftUI\nimport ImagePickerView\n\nstruct PHPickerViewControllerContentView: View {\n    \n    @State var isImagePickerViewPresented = false\n    @State var pickedImages: [UIImage]? = nil\n    \n    var body: some View {\n        VStack(spacing: 12) {\n            Text(\"ImagePickerView\").font(.largeTitle)\n            \n            Button {\n                isImagePickerViewPresented = true\n            } label: {\n                VStack {\n                    Image(systemName: \"camera\")\n                        .font(.largeTitle)\n                }\n            }\n            .sheet(isPresented: $isImagePickerViewPresented) {\n                // filter default is .images; please DO NOT CHOOSE .videos\n                // selectionLimit default is 1; set to 0 to have unlimited selection\n                ImagePickerView(filter: .any(of: [.images, .livePhotos]), selectionLimit: 0, delegate: ImagePickerView.Delegate(isPresented: $isImagePickerViewPresented, didCancel: { (phPickerViewController) in\n                    print(\"Did Cancel: \\(phPickerViewController)\")\n                }, didSelect: { (result) in\n                    let phPickerViewController = result.picker\n                    let images = result.images\n                    print(\"Did Select images: \\(images) from \\(phPickerViewController)\")\n                    pickedImages = images\n                }, didFail: { (imagePickerError) in\n                    let phPickerViewController = imagePickerError.picker\n                    let error = imagePickerError.error\n                    print(\"Did Fail with error: \\(error) in \\(phPickerViewController)\")\n                }))\n            }\n            \n            if pickedImages != nil {\n                ScrollView {\n                    ForEach(pickedImages!, id:\\.self) { image in\n                        Image(uiImage: image)\n                            .resizable()\n                            .frame(width: 66, height: 66)\n                            .cornerRadius(33)\n                    }\n                }\n            }\n            \n            Spacer()\n        }\n    }\n}\n```\n\n## 🪁 Demo project\n\nFor a comprehensive Demo project check out: \n\u003ca href=\"https://github.com/rebeloper/ImagePickerViewDemo\"\u003eImagePickerViewDemo\u003c/a\u003e\n\n## ✍️ Contact\n\n\u003ca href=\"https://rebeloper.com/\"\u003erebeloper.com\u003c/a\u003e / \n\u003ca href=\"https://www.youtube.com/rebeloper/\"\u003eYouTube\u003c/a\u003e / \n\u003ca href=\"https://store.rebeloper.com/\"\u003eShop\u003c/a\u003e / \n\u003ca href=\"https://rebeloper.com/mentoring\"\u003eMentoring\u003c/a\u003e\n\n## 📃 License\n\nThe MIT License (MIT)\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frebeloper%2Fimagepickerview","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frebeloper%2Fimagepickerview","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frebeloper%2Fimagepickerview/lists"}