### Usage Example
Source: https://github.com/silencelove/hxphpicker/blob/main/Pods/GDPerformanceView-Swift/README.md
Examples demonstrating how to start, pause, hide, and configure the performance monitor.
```APIDOC
## Usage Example
Simply start monitoring. Performance view will be added above the status bar automatically.
Also, you can configure appearance as you like or just hide the monitoring view and use its delegate.
You can find example projects [here](https://github.com/dani-gavrilov/GDPerformanceViewExamples).
#### Start Monitoring
By default, monitoring is paused. Call the following command to start or resume monitoring:
```swift
PerformanceMonitor.shared().start()
```
or
```swift
self.performanceView = PerformanceMonitor()
self.performanceView?.start()
```
This won't show the monitoring view if it was hidden previously. To show it call the following command:
```swift
self.performanceView?.show()
```
#### Pause Monitoring
Call the following command to pause monitoring:
```swift
self.performanceView?.pause()
```
This won't hide the monitoring view. To hide it call the following command:
```swift
self.performanceView?.hide()
```
#### Displayed Information
You can change displayed information by changing options of the performance monitor:
```swift
self.performanceView?.performanceViewConfigurator.options = .all
```
You can choose from:
* performance - CPU usage and FPS.
* memory - Memory usage.
* application - Application version with build number.
* device - Device model.
* system - System name with version.
Also you can mix them, but order doesn't matter:
```swift
self.performanceView?.performanceViewConfigurator.options = [.performance, .application, .system]
```
By default, set of [.performance, .application, .system] options is used.
You can also add your custom information by using:
```swift
self.performanceView?.performanceViewConfigurator.userInfo = .custom(string: "Launch date \(Date())")
```
Keep in mind that custom string will not automatically fit the screen, use `\n` if it is too long.
#### Appearance
You can change monitoring view appearance by changing style of the performance monitor:
Call the following command to change output information:
```swift
self.performanceView?.performanceViewConfigurator.style = .dark
```
You can choose from:
* dark - Black background, white text.
* light - White background, black text.
* custom - You can set background color, border color, border width, corner radius, text color and font.
By default, dark style is used.
Also you can override prefersStatusBarHidden and preferredStatusBarStyle to match your expectations:
```swift
self.performanceView?.statusBarConfigurator.statusBarHidden = false
self.performanceView?.statusBarConfigurator.statusBarStyle = .lightContent
```
```
--------------------------------
### Installation
Source: https://github.com/silencelove/hxphpicker/blob/main/Pods/GDPerformanceView-Swift/README.md
Instructions for installing GDPerformanceView-Swift using Carthage or CocoaPods.
```APIDOC
## Installation
Simply add GDPerformanceMonitoring folder with files to your project, or use CocoaPods.
#### Carthage
Create a `Cartfile` that lists the framework and run `carthage update`. Follow the [instructions](https://github.com/Carthage/Carthage#if-youre-building-for-ios) to add `$(SRCROOT)/Carthage/Build/iOS/GDPerformanceView.framework` to an iOS project.
```ruby
github "dani-gavrilov/GDPerformanceView-Swift" ~> 2.1.1
```
Don't forget to import GDPerformanceView by adding:
```swift
import GDPerformanceView
```
#### CocoaPods
You can use [CocoaPods](http://cocoapods.org/) to install `GDPerformanceView` by adding it to your `Podfile`:
```ruby
platform :ios, '8.0'
use_frameworks!
target 'project_name' do
pod 'GDPerformanceView-Swift', '~> 2.1.1'
end
```
Don't forget to import GDPerformanceView by adding:
```swift
import GDPerformanceView_Swift
```
```
--------------------------------
### Start and Control Performance Monitoring
Source: https://github.com/silencelove/hxphpicker/blob/main/Pods/GDPerformanceView-Swift/README.md
Commands to initialize, start, pause, show, and hide the performance monitoring overlay.
```swift
PerformanceMonitor.shared().start()
self.performanceView = PerformanceMonitor()
self.performanceView?.start()
self.performanceView?.show()
self.performanceView?.pause()
self.performanceView?.hide()
```
--------------------------------
### Install GDPerformanceView via Carthage
Source: https://github.com/silencelove/hxphpicker/blob/main/Pods/GDPerformanceView-Swift/README.md
Add the library dependency to your Cartfile to manage the framework via Carthage.
```ruby
github "dani-gavrilov/GDPerformanceView-Swift" ~> 2.1.1
```
--------------------------------
### CocoaPods Installation for HXPHPicker
Source: https://github.com/silencelove/hxphpicker/blob/main/README.md
Instructions for installing HXPHPicker using CocoaPods. Different pods are available for full functionality, or specific modules like Picker, Editor, or Camera. A 'Lite' version is also available for reduced dependencies. Note the separate installation for iOS 10.0+.
```ruby
iOS 12.0+
pod 'HXPHPicker'
/// No Kingfisher
pod `HXPHPicker/Lite`
/// Only Picker
pod `HXPHPicker/Picker`
pod `HXPHPicker/Picker/Lite`
/// Only Editor
pod `HXPHPicker/Editor`
pod `HXPHPicker/Editor/Lite`
/// Only Camera
pod `HXPHPicker/Camera`
/// Does not include location functionality
pod `HXPHPicker/Camera/Lite`
iOS 10.0+
pod 'HXPHPicker-Lite'
pod 'HXPHPicker-Lite/Picker'
pod 'HXPHPicker-Lite/Editor'
pod 'HXPHPicker-Lite/Camera'
```
--------------------------------
### Install GDPerformanceView via CocoaPods
Source: https://github.com/silencelove/hxphpicker/blob/main/Pods/GDPerformanceView-Swift/README.md
Add the library dependency to your Podfile to manage the framework via CocoaPods.
```ruby
platform :ios, '8.0'
use_frameworks!
target 'project_name' do
pod 'GDPerformanceView-Swift', '~> 2.1.1'
end
```
--------------------------------
### Implement Camera Capture with HXPHPicker
Source: https://context7.com/silencelove/hxphpicker/llms.txt
Shows how to configure the CameraController to capture photos or videos. Provides examples for both the static closure-based capture method and the delegate-based approach for handling results and creating PhotoAsset objects.
```swift
import HXPHPicker
import CoreLocation
class CameraExample: UIViewController, CameraControllerDelegate {
func openCamera() {
var config = CameraConfiguration()
config.modalPresentationStyle = .fullScreen
CameraController.capture(config: config, type: .all) { result, location in
switch result {
case .image(let image):
print("Captured photo: \(image.size)")
case .video(let videoURL):
print("Recorded video: \(videoURL)")
}
}
}
func cameraController(_ cameraController: CameraController, didFinishWithResult result: CameraController.Result, location: CLLocation?) {
switch result {
case .image(let image):
let localImage = LocalImageAsset(image: image)
let photoAsset = PhotoAsset(localImageAsset: localImage)
print("Created asset: \(photoAsset)")
case .video(let videoURL):
let localVideo = LocalVideoAsset(videoURL: videoURL)
let videoAsset = PhotoAsset(localVideoAsset: localVideo)
print("Created video asset: \(videoAsset)")
}
cameraController.dismiss(animated: true)
}
}
```
--------------------------------
### Carthage Installation for HXPHPicker
Source: https://github.com/silencelove/hxphpicker/blob/main/README.md
This code demonstrates how to add HXPHPicker as a dependency in your project using Carthage. After adding the line to your Cartfile, run the Carthage update command.
```bash
github "SilenceLove/HXPHPicker"
```
--------------------------------
### Kingfisher Installation with CocoaPods
Source: https://github.com/silencelove/hxphpicker/blob/main/Pods/Kingfisher/README.md
Provides the necessary configuration for installing Kingfisher version 7.0.0 or later using CocoaPods. This includes setting the source repository, platform, and specifying the Kingfisher pod in the target's podfile.
```ruby
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '12.0'
use_frameworks!
target 'MyApp' do
pod 'Kingfisher', '~> 7.0'
end
```
--------------------------------
### Swift Package Manager Installation for HXPHPicker
Source: https://github.com/silencelove/hxphpicker/blob/main/README.md
This snippet shows how to add HXPHPicker to your Xcode project using Swift Package Manager. Ensure you are using Xcode 12.0+ for resource and localization file support.
```swift
dependencies: [
.package(url: "https://github.com/SilenceLove/HXPHPicker.git", .upToNextMajor(from: "2.0.0"))
]
```
--------------------------------
### Presenting the Photo Picker
Source: https://github.com/silencelove/hxphpicker/blob/main/README.md
Demonstrates how to initialize and present the PhotoPickerController using either a standard instance or the static convenience method. It also shows how to implement the delegate to handle selection results.
```swift
import HXPHPicker
class ViewController: UIViewController {
func presentPickerController() {
let config = PickerConfiguration.default
let pickerController = PhotoPickerController(picker: config)
pickerController.pickerDelegate = self
present(pickerController, animated: true, completion: nil)
Photo.picker(config) { result, pickerController in
} cancel: { pickerController in
}
}
}
extension ViewController: PhotoPickerControllerDelegate {
func pickerController(_ pickerController: PhotoPickerController, didFinishSelection result: PickerResult) {
result.getImage { (image, photoAsset, index) in
if let image = image { print("success", image) }
} completionHandler: { (images) in print(images) }
}
func pickerController(didCancel pickerController: PhotoPickerController) {}
}
```
--------------------------------
### Manage and retrieve PhotoAsset data
Source: https://context7.com/silencelove/hxphpicker/llms.txt
Shows how to initialize PhotoAsset instances from various sources including PHAssets, local files, and network URLs, and how to extract media data or URLs with compression.
```swift
import HXPHPicker
func workingWithPhotoAssets() {
let photoAsset = PhotoAsset(asset: phAsset)
photoAsset.getImage(compressionQuality: 0.8) { image in
if let image = image {
print("Image size: \(image.size)")
}
}
let compression = PhotoAsset.Compression(imageCompressionQuality: 0.9)
photoAsset.getURL(compression: compression) { result in
switch result {
case .success(let urlResult):
print("URL: \(urlResult.url)")
case .failure(let error):
print("Error: \(error)")
}
}
}
```
--------------------------------
### Configure and Present Video Editor with HXPHPicker
Source: https://context7.com/silencelove/hxphpicker/llms.txt
Demonstrates how to initialize the EditorViewController with custom video configurations, including time limits and export quality. It shows both local file editing and network video handling using completion handlers.
```swift
import HXPHPicker
class VideoEditorExample: UIViewController, EditorViewControllerDelegate {
func editVideo(at url: URL) {
var config = EditorConfiguration()
config.video.cropTime.maximumTime = 60
config.video.cropTime.minimumTime = 3
config.video.preset = .highestQuality
config.video.quality = 6
config.video.music.tintColor = .systemBlue
let asset = EditorAsset(type: .video(url))
let editor = EditorViewController(asset, config: config, delegate: self)
present(editor, animated: true)
}
func editNetworkVideo(url: URL) {
let config = EditorConfiguration()
let asset = EditorAsset(type: .networkVideo(url))
let editor = EditorViewController(asset, config: config) { result, controller in
if let result = result {
switch result {
case .video(let videoResult, let editedData):
print("Video URL: \(videoResult.urlConfig.url)")
default:
break
}
}
controller.dismiss(animated: true)
} cancel: { controller in
controller.dismiss(animated: true)
}
present(editor, animated: true)
}
}
```
--------------------------------
### Display PhotoBrowser for Asset Preview
Source: https://context7.com/silencelove/hxphpicker/llms.txt
Demonstrates how to initialize and display a standalone photo browser with custom configurations. It includes handlers for delete actions and long-press interactions.
```swift
import HXPHPicker
class PhotoBrowserExample: UIViewController {
var assets: [PhotoAsset] = []
var collectionView: UICollectionView!
func showPhotoBrowser(at index: Int) {
var config = PhotoBrowser.Configuration()
config.showDelete = true
config.modalPresentationStyle = .fullScreen
let cell = collectionView.cellForItem(at: IndexPath(item: index, section: 0))
let thumbnailImage = (cell as? PhotoCell)?.imageView.image
PhotoBrowser.show(
assets,
pageIndex: index,
config: config,
transitionalImage: thumbnailImage
) { [weak self] index in
self?.collectionView.cellForItem(at: IndexPath(item: index, section: 0))
} deleteAssetHandler: { index, photoAsset, photoBrowser in
PhotoTools.showAlert(
viewController: photoBrowser,
title: "Delete this photo?",
leftActionTitle: "Delete",
leftHandler: { _ in
photoBrowser.deleteCurrentPreviewPhotoAsset()
},
rightActionTitle: "Cancel"
) { _ in }
} longPressHandler: { index, photoAsset, photoBrowser in
print("Long pressed on asset at index: \(index)")
}
}
}
```
--------------------------------
### Photo Picker - Basic Usage (Swift)
Source: https://context7.com/silencelove/hxphpicker/llms.txt
Demonstrates the basic closure-based API for presenting the photo picker. It allows users to select photos and videos with a WeChat-style interface and retrieve selected assets or images. Dependencies include the HXPHPicker framework.
```swift
import HXPHPicker
class ViewController: UIViewController {
var selectedAssets: [PhotoAsset] = []
var isOriginal: Bool = false
func presentPhotoPicker() {
// Use default WeChat-style configuration
let config = PickerConfiguration.default
// Method 1: Using closure-based API
Photo.picker(
config,
selectedAssets: selectedAssets
) { result, pickerController in
// Selection completed
// result.photoAssets - Selected assets array
// result.isOriginal - Whether original image is selected
self.selectedAssets = result.photoAssets
self.isOriginal = result.isOriginal
// Get UIImages from selection
result.getImage {
image, photoAsset, index in
if let image = image {
print("Got image at index \(index): \(image.size)")
}
} completionHandler: {
images in
print("All \(images.count) images loaded")
}
} cancel: {
pickerController in
print("User cancelled selection")
}
}
}
```
--------------------------------
### SwiftUI Image Loading with KFImage
Source: https://github.com/silencelove/hxphpicker/blob/main/Pods/Kingfisher/README.md
Demonstrates how to use Kingfisher's KFImage view for loading images within a SwiftUI view. This approach leverages the same fluent API as the KF builder but is specifically designed for SwiftUI integration, allowing for declarative image loading with placeholders, processors, and callbacks.
```swift
struct ContentView: View {
var body: some View {
KFImage.url(url)
.placeholder(placeholderImage)
.setProcessor(processor)
.loadDiskFileSynchronously()
.cacheMemoryOnly()
.fade(duration: 0.25)
.lowDataModeSource(.network(lowResolutionURL))
.onProgress { receivedSize, totalSize in }
.onSuccess { result in }
.onFailure { error in }
}
}
```
--------------------------------
### Photo Picker - Delegate-Based Usage (Swift)
Source: https://context7.com/silencelove/hxphpicker/llms.txt
Shows how to use the delegate-based approach with PhotoPickerController for more control over the picker. This method allows handling selection completion, cancellation, and dismissal, including retrieving URLs for selected media. Dependencies include the HXPHPicker framework.
```swift
import HXPHPicker
class ViewController: UIViewController, PhotoPickerControllerDelegate {
var selectedAssets: [PhotoAsset] = []
var localCameraAssets: [PhotoAsset] = []
func presentPickerWithDelegate() {
let config = PickerConfiguration()
let pickerController = PhotoPickerController(picker: config, delegate: self)
// Set previously selected assets
pickerController.selectedAssetArray = selectedAssets
// Set whether original image was selected
pickerController.isOriginal = false
// Set local camera assets from previous session
pickerController.localCameraAssetArray = localCameraAssets
present(pickerController, animated: true)
}
// MARK: - PhotoPickerControllerDelegate
func pickerController(_ pickerController: PhotoPickerController,
didFinishSelection result: PickerResult) {
// Get URLs for all selected assets
result.getURLs {
urlResult, photoAsset, index in
switch urlResult {
case .success(let response):
if response.mediaType == .photo {
print("Photo URL: \(response.url)")
} else {
print("Video URL: \(response.url)")
}
case .failure(let error):
print("Failed to get URL: \(error)")
}
} completionHandler: {
urls in
print("All URLs: \(urls)")
}
}
func pickerController(didCancel pickerController: PhotoPickerController) {
print("Selection cancelled")
}
func pickerController(_ pickerController: PhotoPickerController,
didDismissComplete localCameraAssetArray: [PhotoAsset]) {
// Save camera assets for next session
self.localCameraAssets = localCameraAssetArray
}
}
```
--------------------------------
### Configure HXPHPicker settings
Source: https://context7.com/silencelove/hxphpicker/llms.txt
Demonstrates how to customize the picker's appearance, selection modes, file size limits, and navigation styles using the PickerConfiguration object.
```swift
import HXPHPicker
func createCustomConfiguration() -> PickerConfiguration {
var config = PickerConfiguration()
config.languageType = .english
config.appearanceStyle = .varied
config.selectMode = .multiple
config.selectOptions = [.photo, .video, .gifPhoto, .livePhoto]
config.allowSelectedTogether = true
config.maximumSelectedCount = 9
config.maximumSelectedVideoDuration = 60
config.photoSelectionTapAction = .preview
config.albumShowMode = .popup
config.allowSyncICloudWhenSelectPhoto = true
return config
}
```
--------------------------------
### Advanced Image Loading with Kingfisher Options
Source: https://github.com/silencelove/hxphpicker/blob/main/Pods/Kingfisher/README.md
Illustrates advanced image loading in Kingfisher, including downsampling, corner radius processing, setting a placeholder, activity indicator, transition effects, and caching the original image. It also includes completion handlers for success and failure.
```swift
let url = URL(string: "https://example.com/high_resolution_image.png")
let processor = DownsamplingImageProcessor(size: imageView.bounds.size)
|> RoundCornerImageProcessor(cornerRadius: 20)
imagView.kf.indicatorType = .activity
imagView.kf.setImage(
with: url,
placeholder: UIImage(named: "placeholderImage"),
options: [
.processor(processor),
.scaleFactor(UIScreen.main.scale),
.transition(.fade(1)),
.cacheOriginalImage
])
{
result in
switch result {
case .success(let value):
print("Task done for: \(value.source.url?.absoluteString ?? "")")
case .failure(let error):
print("Job failed: \(error.localizedDescription)")
}
}
```
--------------------------------
### Image Editor Configuration and Usage with Swift
Source: https://context7.com/silencelove/hxphpicker/llms.txt
Shows how to use the EditorViewController for image editing tasks. It covers configuring crop settings, brush colors, mosaic effects, and handling both local images and network images.
```swift
import HXPHPicker
class ImageEditorExample: UIViewController, EditorViewControllerDelegate {
func editImage(_ image: UIImage) {
var config = EditorConfiguration()
// Configure crop settings
config.cropSize.aspectRatios = [
.init(width: 0, height: 0), // Free ratio
.init(width: 1, height: 1), // Square
.init(width: 4, height: 3),
.init(width: 16, height: 9)
]
config.cropSize.isRoundCrop = false
config.cropSize.isFixedRatio = false
// Configure brush/drawing
config.brush.colors = [
.init(color: .white),
.init(color: .black),
.init(color: .red),
.init(color: .yellow),
.init(color: .green),
.init(color: .blue)
]
config.brush.defaultColorIndex = 0
config.brush.lineWidth = 5
// Configure mosaic
config.mosaic.mosaiclineWidth = 25
config.mosaic.smearWidth = 30
// Create editor asset
let asset = EditorAsset(type: .image(image))
// Present editor
let editor = EditorViewController(asset, config: config, delegate: self)
present(editor, animated: true)
}
func editImageFromURL(_ url: URL) {
let config = EditorConfiguration()
let asset = EditorAsset(type: .networkImage(url))
let editor = EditorViewController(asset, config: config) { result, controller in
// Completion handler
if let result = result {
switch result {
case .image(let imageResult, _):
print("Edited image URL: \(imageResult.urlConfig.url)")
print("Thumbnail: \(imageResult.image)")
default:
break
}
}
controller.dismiss(animated: true)
} cancel: { controller in
controller.dismiss(animated: true)
}
present(editor, animated: true)
}
// MARK: - EditorViewControllerDelegate
func editorViewController(_ editorViewController: EditorViewController,
didFinish asset: EditorAsset) {
if let result = asset.result {
switch result {
case .image(let imageResult, let editedData):
print("Image saved to: \(imageResult.urlConfig.url)")
print("Crop aspect ratio: \(editedData.cropSize?.aspectRatio ?? .zero)")
default:
break
}
}
editorViewController.dismiss(animated: true)
}
func editorViewController(didCancel editorViewController: EditorViewController) {
editorViewController.dismiss(animated: true)
}
}
```
--------------------------------
### PhotoAsset Data Persistence with Swift
Source: https://context7.com/silencelove/hxphpicker/llms.txt
Demonstrates how to save and load PhotoAsset objects using encoding and decoding for data persistence. It utilizes JSONEncoder and JSONDecoder to handle the data serialization to a file.
```swift
import HXPHPicker
class AssetPersistence {
let fileURL = FileManager.default.temporaryDirectory
.appendingPathComponent("savedAssets.data")
func saveAssets(_ assets: [PhotoAsset]) {
var dataArray: [Data] = []
for asset in assets {
if let data = asset.encode() {
dataArray.append(data)
}
}
// Save to file
let combinedData = try? JSONEncoder().encode(dataArray)
try? combinedData?.write(to: fileURL)
}
func loadAssets() -> [PhotoAsset] {
guard let combinedData = try? Data(contentsOf: fileURL),
let dataArray = try? JSONDecoder().decode([Data].self, from: combinedData) else {
return []
}
return dataArray.compactMap { PhotoAsset.decoder(data: $0) }
}
}
```
--------------------------------
### Configure Displayed Performance Metrics
Source: https://github.com/silencelove/hxphpicker/blob/main/Pods/GDPerformanceView-Swift/README.md
Customize the information displayed in the performance monitor, such as CPU, memory, or system details.
```swift
self.performanceView?.performanceViewConfigurator.options = .all
self.performanceView?.performanceViewConfigurator.options = [.performance, .application, .system]
self.performanceView?.performanceViewConfigurator.userInfo = .custom(string: "Launch date \(Date())")
```
--------------------------------
### Image Loading with KF Builder and kf Extension in Swift
Source: https://github.com/silencelove/hxphpicker/blob/main/Pods/Kingfisher/README.md
Compares two methods for image loading using Kingfisher: the direct kf extension and the KF builder with method chaining. Both achieve the same result of loading an image into an ImageView with various options for caching, processing, and transitions. The KF builder offers a more fluent API.
```swift
imageView.kf.setImage(
with: url,
placeholder: placeholderImage,
options: [
.processor(processor),
.loadDiskFileSynchronously,
.cacheOriginalImage,
.transition(.fade(0.25)),
.lowDataMode(.network(lowResolutionURL))
],
progressBlock: { receivedSize, totalSize in
// Progress updated
},
completionHandler: { result in
// Done
}
)
```
```swift
KF.url(url)
.placeholder(placeholderImage)
.setProcessor(processor)
.loadDiskFileSynchronously()
.cacheMemoryOnly()
.fade(duration: 0.25)
.lowDataModeSource(.network(lowResolutionURL))
.onProgress { receivedSize, totalSize in }
.onSuccess { result in }
.onFailure { error in }
.set(to: imageView)
```
--------------------------------
### Integrate Embeddable PhotoPickerView
Source: https://context7.com/silencelove/hxphpicker/llms.txt
Shows how to embed a photo picker directly into a view hierarchy. It covers configuration, asset fetching, and handling selection events via the PhotoPickerViewDelegate.
```swift
import HXPHPicker
class EmbeddedPickerExample: UIViewController, PhotoPickerViewDelegate {
var pickerView: PhotoPickerView!
var manager: PickerManager!
override func viewDidLoad() {
super.viewDidLoad()
var config = PickerConfiguration()
config.selectOptions = [.photo, .video]
config.maximumSelectedCount = 9
manager = PickerManager()
manager.config = config
pickerView = PhotoPickerView(
manager: manager,
scrollDirection: .horizontal,
delegate: self
)
pickerView.frame = CGRect(x: 0, y: 100, width: view.bounds.width, height: 200)
view.addSubview(pickerView)
pickerView.fetchAsset()
}
func getSelectedAssets() -> [PhotoAsset] {
return manager.selectedAssetArray
}
func photoPickerView(_ photoPickerView: PhotoPickerView, didSelectItemAt index: Int, photoAsset: PhotoAsset) {
print("Selected: \(photoAsset)")
}
}
```
--------------------------------
### PhotoPickerController (Delegate-based API)
Source: https://context7.com/silencelove/hxphpicker/llms.txt
The delegate-based approach offers finer control over the picker lifecycle, state management, and asset processing through the PhotoPickerControllerDelegate protocol.
```APIDOC
## PhotoPickerController (Delegate-based)
### Description
Use the PhotoPickerController class to manage complex selection workflows, including state persistence and custom delegate callbacks.
### Method
Initializer
### Parameters
- **picker** (PickerConfiguration) - Required - Configuration instance.
- **delegate** (PhotoPickerControllerDelegate) - Required - The object conforming to the delegate protocol.
### Delegate Methods
- **pickerController(_:didFinishSelection:)** - Triggered when the user confirms selection.
- **pickerController(didCancel:)** - Triggered when the user cancels.
- **pickerController(_:didDismissComplete:)** - Triggered when the controller is dismissed, useful for saving local camera assets.
### Response
#### Success Response
- **result** (PickerResult) - Provides methods like getURLs or getImage to retrieve media data asynchronously.
```
--------------------------------
### Display Image in SwiftUI with Kingfisher
Source: https://github.com/silencelove/hxphpicker/blob/main/Pods/Kingfisher/README.md
Shows how to use Kingfisher within a SwiftUI view to display an image from a URL. The KFImage view handles the asynchronous loading and caching of the image.
```swift
import SwiftUI
import Kingfisher
struct ContentView: View {
var body: some View {
KFImage(URL(string: "https://example.com/image.png")!)
}
}
```
--------------------------------
### Retrieving Media Assets
Source: https://github.com/silencelove/hxphpicker/blob/main/README.md
Shows how to extract media content from a PhotoAsset object. You can retrieve a UIImage directly or obtain a URL for the asset, which includes handling for different media types and sources.
```swift
photoAsset.getImage(compressionQuality: compressionQuality) { image in
print(image)
}
photoAsset.getURL(compression: compression) { result in
switch result {
case .success(let urlResult):
print(urlResult.url)
case .failure(let error):
print(error)
}
}
```
--------------------------------
### Info.plist Keys for HXPHPicker Permissions
Source: https://github.com/silencelove/hxphpicker/blob/main/README.md
This table lists the necessary keys to add to your app's Info.plist file to grant permissions for HXPHPicker's features. These include access to the photo library, camera, and microphone, as well as specific settings for iOS 14+.
```xml
NSPhotoLibraryUsageDescription
Allow access to album
NSPhotoLibraryAddUsageDescription
Allow to save pictures to album
PHPhotoLibraryPreventAutomaticLimitedAccessAlert
YES
NSCameraUsageDescription
Allow camera
NSMicrophoneUsageDescription
Allow microphone
```
--------------------------------
### Customize Performance View Appearance
Source: https://github.com/silencelove/hxphpicker/blob/main/Pods/GDPerformanceView-Swift/README.md
Adjust the visual style of the performance monitor and configure status bar behavior.
```swift
self.performanceView?.performanceViewConfigurator.style = .dark
self.performanceView?.statusBarConfigurator.statusBarHidden = false
self.performanceView?.statusBarConfigurator.statusBarStyle = .lightContent
```
--------------------------------
### Set Performance View Delegate (Swift)
Source: https://github.com/silencelove/hxphpicker/blob/main/Pods/GDPerformanceView-Swift/README.md
This snippet demonstrates how to set the delegate for the performance view and implement the `performanceMonitor(didReport:)` method to receive performance reports. The delegate receives reports containing CPU usage, FPS, and memory usage.
```swift
self.performanceView?.delegate = self
```
```swift
func performanceMonitor(didReport performanceReport: PerformanceReport) {
print(performanceReport.cpuUsage, performanceReport.fps, performanceReport.memoryUsage.used, performanceReport.memoryUsage.total)
}
```
--------------------------------
### Photo.picker (Closure-based API)
Source: https://context7.com/silencelove/hxphpicker/llms.txt
The closure-based API provides a simple way to present the photo picker and handle selection results, cancellation, and image retrieval.
```APIDOC
## Photo.picker (Closure-based)
### Description
This method presents the photo picker using a default configuration and handles the selection process via completion closures.
### Method
Static Method
### Parameters
- **config** (PickerConfiguration) - Required - The configuration object defining picker behavior.
- **selectedAssets** ([PhotoAsset]) - Optional - Previously selected assets to pre-populate the picker.
- **completion** (Closure) - Required - Called when selection is finished; provides PickerResult and the controller instance.
- **cancel** (Closure) - Optional - Called when the user dismisses the picker without making a selection.
### Request Example
Photo.picker(config, selectedAssets: assets) { result, controller in ... } cancel: { controller in ... }
### Response
#### Success Response
- **result** (PickerResult) - Contains selected photoAssets and isOriginal flag.
- **controller** (PhotoPickerController) - The active picker controller instance.
```
--------------------------------
### PhotoAsset Data Persistence
Source: https://context7.com/silencelove/hxphpicker/llms.txt
Methods for encoding and decoding PhotoAsset objects to enable data persistence across application sessions.
```APIDOC
## PhotoAsset Persistence
### Description
Provides mechanisms to serialize PhotoAsset objects into Data format for storage and reconstruct them from stored data.
### Methods
- **saveAssets([PhotoAsset])**: Encodes an array of assets into a JSON-serialized Data array and writes to a temporary file.
- **loadAssets() -> [PhotoAsset]**: Reads the stored data file and decodes it back into an array of PhotoAsset objects.
### Request Example
let assets = [photoAsset1, photoAsset2]
saveAssets(assets)
### Response
- **Success**: Returns an array of [PhotoAsset] objects upon successful decoding.
```
--------------------------------
### Set Image in UIImageView with Kingfisher
Source: https://github.com/silencelove/hxphpicker/blob/main/Pods/Kingfisher/README.md
Demonstrates the basic usage of Kingfisher to set an image in a UIImageView directly from a URL. The library handles downloading, caching, and displaying the image asynchronously. Subsequent requests for the same URL will retrieve the image from the cache.
```swift
import Kingfisher
let url = URL(string: "https://example.com/image.png")
imagineView.kf.setImage(with: url)
```
--------------------------------
### Manage Photo Library Authorization
Source: https://context7.com/silencelove/hxphpicker/llms.txt
Provides utilities for checking and requesting photo library access using AssetManager. It handles various authorization states including limited access.
```swift
import HXPHPicker
import Photos
class AuthorizationExample {
func checkAuthorization() {
let status = AssetManager.authorizationStatus()
switch status {
case .notDetermined:
AssetManager.requestAuthorization { newStatus in
if newStatus == .authorized {
print("Full access granted")
}
}
case .authorized:
print("Full access")
default:
break
}
}
func fetchAsset(identifier: String) -> PHAsset? {
return AssetManager.fetchAsset(withLocalIdentifier: identifier)
}
}
```
--------------------------------
### EditorViewController Image Editing
Source: https://context7.com/silencelove/hxphpicker/llms.txt
Configuration and presentation of the EditorViewController for image manipulation tasks.
```APIDOC
## EditorViewController
### Description
Handles image editing including cropping, brush strokes, mosaic effects, and sticker application.
### Configuration
- **EditorConfiguration**: Object used to define crop aspect ratios, brush colors, line widths, and mosaic settings.
### Usage
1. Initialize EditorConfiguration.
2. Create an EditorAsset using a local UIImage or a network URL.
3. Present the EditorViewController with the configuration and asset.
### Delegate Methods
- **didFinish(asset: EditorAsset)**: Triggered when the user completes the editing process.
- **didCancel()**: Triggered when the user cancels the editing session.
### Response Example
{
"status": "success",
"result": {
"type": "image",
"url": "file:///path/to/edited/image.jpg",
"crop_aspect_ratio": "16:9"
}
}
```
--------------------------------
### Configure Performance View Interactors (Swift)
Source: https://github.com/silencelove/hxphpicker/blob/main/Pods/GDPerformanceView-Swift/README.md
This snippet shows how to set gesture recognizers as interactors for the performance view. You can assign an array of gesture recognizers to `performanceViewConfigurator.interactors`. Setting interactors to `nil` removes them, allowing touches to pass through.
```swift
self.performanceView?.performanceViewConfigurator.interactors = [tapGesture, swipeGesture]
```
```swift
self.performanceView?.performanceViewConfigurator.interactors = nil
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.