Skip to content

Commit cb253e1

Browse files
authored
Merge pull request #11 from bullinnyc/add-url-request-parameter
Add url request parameter.
2 parents 6babc1e + dcdcd55 commit cb253e1

11 files changed

Lines changed: 265 additions & 245 deletions

File tree

.swiftpm/xcode/xcshareddata/xcschemes/CachedAsyncImage-Package.xcscheme

Lines changed: 0 additions & 106 deletions
This file was deleted.

.swiftpm/xcode/xcshareddata/xcschemes/ExampleCachedAsyncImage.xcscheme

Lines changed: 0 additions & 66 deletions
This file was deleted.

Examples/ContentView.swift

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import SwiftUI
1010
import CachedAsyncImage
1111

12-
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, visionOS 1.0, *)
1312
struct ContentView: View {
1413
// MARK: - Private Properties
1514

@@ -20,7 +19,7 @@ struct ContentView: View {
2019
"https://image.tmdb.org/t/p/original/arw2vcBveWOVZr6pxd9XTd1TdQa.jpg"
2120
]
2221

23-
private static let standartPadding: CGFloat = 20
22+
private static let standartPadding: CGFloat = 16
2423

2524
// MARK: - Initializers
2625

@@ -36,14 +35,14 @@ struct ContentView: View {
3635

3736
var body: some View {
3837
ZStack {
39-
Color(RM.snow)
38+
Color.white
4039
.ignoresSafeArea()
4140

4241
GeometryReader { geometry in
4342
let size = geometry.size
4443

4544
ScrollView {
46-
VStack(spacing: 20) {
45+
VStack(spacing: 16) {
4746
ForEach(posters, id: \.self) { url in
4847
CachedAsyncImage(
4948
url: url,
@@ -97,9 +96,8 @@ struct ContentView: View {
9796

9897
// MARK: - Ext. Configure views
9998

100-
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, visionOS 1.0, *)
10199
extension ContentView {
102-
func placeholder(_ progress: String) -> some View {
100+
private func placeholder(_ progress: String) -> some View {
103101
ZStack {
104102
Color.yellow
105103

@@ -113,7 +111,10 @@ extension ContentView {
113111
}
114112
}
115113

116-
func error(_ error: String, action: (() -> Void)? = nil) -> some View {
114+
private func error(
115+
_ error: String,
116+
action: (() -> Void)? = nil
117+
) -> some View {
117118
ZStack {
118119
Color.yellow
119120

@@ -135,7 +136,7 @@ extension ContentView {
135136
}
136137
}
137138

138-
func retry(action: (() -> Void)?) -> some View {
139+
private func retry(action: (() -> Void)?) -> some View {
139140
Button(
140141
action: { action?() },
141142
label: {
@@ -146,12 +147,3 @@ extension ContentView {
146147
)
147148
}
148149
}
149-
150-
// MARK: - Preview Provider
151-
152-
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, visionOS 1.0, *)
153-
struct ContentView_Previews: PreviewProvider {
154-
static var previews: some View {
155-
ContentView()
156-
}
157-
}

Package.swift

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@ let package = Package(
1818
.library(
1919
name: "CachedAsyncImage",
2020
targets: ["CachedAsyncImage"]
21-
),
22-
.library(
23-
name: "ExampleCachedAsyncImage",
24-
targets: ["Examples"]
2521
)
2622
],
2723
targets: [
@@ -30,11 +26,6 @@ let package = Package(
3026
.target(
3127
name: "CachedAsyncImage"
3228
),
33-
.target(
34-
name: "Examples",
35-
dependencies: ["CachedAsyncImage"],
36-
path: "Examples"
37-
),
3829
.testTarget(
3930
name: "CachedAsyncImageTests",
4031
dependencies: ["CachedAsyncImage"]

README.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,28 @@ init() {
124124
}
125125
```
126126

127-
### You can also read this value from within a view to access the image cache management
127+
### Get cached image, remove cached image or image cache if needed.
128128

129129
```swift
130130
struct MyView: View {
131131
@ImageCache private var imageCache
132132

133133
// ...
134+
135+
// Get cached image.
136+
private func getCachedImage(for url: URL) -> UIImage? {
137+
imageCache[url]
138+
}
139+
140+
// Remove cached image.
141+
private func removeCachedImage(for url: URL) {
142+
imageCache[url] = nil
143+
}
144+
145+
// Remove image cache.
146+
private func removeImageCache() {
147+
imageCache.removeCache()
148+
}
134149
}
135150
```
136151

Sources/CachedAsyncImage/Resources/ResourcesManager.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ import SwiftUI
1414
#endif
1515

1616
/// Resources manager typealias.
17-
public typealias RM = ResourcesManager
17+
typealias RM = ResourcesManager
1818

1919
/// Resources manager.
20-
public final class ResourcesManager {
20+
final class ResourcesManager {
2121
// MARK: - Public Properties
2222

2323
/// An object that stores color data.
24-
public static let snow = getColor(with: "snow")
24+
static let snow = getColor(with: "snow")
2525

2626
// MARK: - Public Methods
2727

@@ -30,7 +30,7 @@ public final class ResourcesManager {
3030
/// - Parameter name: Image name.
3131
///
3232
/// - Returns: An initialized image object or `nil` if the object was not found in the resources.
33-
public static func image(_ name: String) -> UIImage? {
33+
static func image(_ name: String) -> UIImage? {
3434
UIImage(named: name, in: Bundle.module, with: nil)
3535
}
3636

@@ -52,14 +52,14 @@ public final class ResourcesManager {
5252
import AppKit
5353

5454
/// Resources manager typealias.
55-
public typealias RM = ResourcesManager
55+
typealias RM = ResourcesManager
5656

5757
/// Resources manager.
58-
public final class ResourcesManager {
58+
final class ResourcesManager {
5959
// MARK: - Public Properties
6060

6161
/// An object that stores color data.
62-
public static let snow = NSColor(
62+
static let snow = NSColor(
6363
named: NSColor.Name("snow"),
6464
bundle: Bundle.module
6565
) ?? NSColor()
@@ -71,7 +71,7 @@ public final class ResourcesManager {
7171
/// - Parameter name: Image name.
7272
///
7373
/// - Returns: An initialized image object or `nil` if the object was not found in the resources.
74-
public static func image(_ name: String) -> NSImage? {
74+
static func image(_ name: String) -> NSImage? {
7575
Bundle.module.image(forResource: NSImage.Name(name))
7676
}
7777
}

0 commit comments

Comments
 (0)