Skip to content

Commit 6fadd34

Browse files
authored
update readme
1 parent d521456 commit 6fadd34

File tree

1 file changed

+159
-1
lines changed

1 file changed

+159
-1
lines changed

README.md

+159-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,159 @@
1-
# PhotoConcurrencyManager
1+
# PhotoConcurrencyManager
2+
3+
A concurrent photo loading and caching manager for iOS that provides efficient photo asset handling with support for both high and low-quality image loading states.
4+
5+
## Features
6+
7+
- ✨ Concurrent photo loading with async/await support
8+
- 🎯 Multiple image quality delivery modes (low/high quality)
9+
- 💾 Built-in memory caching
10+
- 🔄 Prefetching support for smooth scrolling
11+
- 📱 iCloud photo access handling
12+
- 🎨 Flexible image loading configurations
13+
- 🏃‍♂️ Performance optimized for scrolling
14+
15+
## Installation
16+
17+
### Swift Package Manager
18+
19+
Add the following to your `Package.swift` file:
20+
21+
```swift
22+
dependencies: [
23+
.package(url: "https://github.com/sozohoy/PhotoConcurrencyManager", from: "1.0.0")
24+
]
25+
```
26+
27+
## Usage
28+
29+
### Basic Usage
30+
31+
```swift
32+
let manager = PhotoConcurrencyManager()
33+
34+
// Request photo library authorization
35+
let isAuthorized = await manager.requestAuthorization()
36+
37+
// Load an image
38+
let stream = manager.loadImage(
39+
asset: photoAsset,
40+
targetSize: CGSize(width: 300, height: 300),
41+
contentMode: .aspectFill,
42+
configuration: .thumbnail
43+
)
44+
45+
for try await quality in stream {
46+
switch quality {
47+
case .low(let image):
48+
// Handle low quality image (e.g., show as placeholder)
49+
case .high(let image):
50+
// Handle high quality image
51+
}
52+
}
53+
```
54+
55+
### Prefetching Images
56+
57+
```swift
58+
// Start prefetching
59+
manager.prefetchImages(
60+
for: assets,
61+
targetSize: CGSize(width: 300, height: 300),
62+
contentMode: .aspectFill,
63+
configuration: .scrolling
64+
)
65+
66+
// Cancel prefetching when needed
67+
manager.cancelPrefetching(
68+
for: assets,
69+
targetSize: CGSize(width: 300, height: 300),
70+
contentMode: .aspectFill,
71+
configuration: .scrolling
72+
)
73+
```
74+
75+
### Loading Images While Scrolling
76+
77+
```swift
78+
let image = try await manager.loadImageWhenScrolling(
79+
asset: asset,
80+
targetSize: CGSize(width: 300, height: 300),
81+
contentMode: .aspectFill,
82+
configuration: .scrolling
83+
)
84+
```
85+
86+
## Configuration Options
87+
88+
### Image Quality Configuration
89+
90+
The library provides several preset configurations:
91+
92+
```swift
93+
// Default configuration for optimal quality/performance balance
94+
.opportunisticFit
95+
96+
// High quality synchronous loading
97+
.highQualitySync
98+
99+
// Fast loading for thumbnails
100+
.thumbnail
101+
102+
// Optimized for scroll performance
103+
.scrolling
104+
```
105+
106+
### Custom Configuration
107+
108+
Create custom configurations by specifying:
109+
- Synchronous/Asynchronous loading
110+
- Delivery mode (fast/opportunistic/high quality)
111+
- Content mode (aspect fit/fill)
112+
- iCloud access mode
113+
- Resize mode
114+
- Version requirements
115+
116+
```swift
117+
let customConfig = PhotoImageOptions.Configuration(
118+
synchronousMode: .async,
119+
deliveryMode: .highQuality,
120+
contentMode: .aspectFill,
121+
iCloudAccessMode: .allowed,
122+
resizeMode: .exact,
123+
version: .current
124+
)
125+
```
126+
127+
## Error Handling
128+
129+
The library provides detailed error cases:
130+
131+
```swift
132+
public enum ImageLoadingError: Error {
133+
case loadingFailed(Error)
134+
case cancelled
135+
case noImage
136+
case unauthorized
137+
}
138+
```
139+
140+
## Performance Considerations
141+
142+
- Built-in memory cache management with configurable size limits
143+
- Automatic cache cleanup
144+
- Optimized for scroll performance with dedicated configurations
145+
- Prefetching support for smooth scrolling experiences
146+
147+
## Requirements
148+
149+
- iOS 16.0+
150+
- Swift 6.0+
151+
- Xcode 14.0+
152+
153+
## License
154+
155+
This library is released under the MIT license. See [LICENSE](https://github.com/sozohoy/PhotoConcurrencyManager/blob/main/LICENSE) for details.
156+
157+
## Contributing
158+
159+
Contributions are welcome! Please feel free to submit a Pull Request.

0 commit comments

Comments
 (0)