File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 99import SwiftUI
1010import CachedAsyncImage
1111
12+ @available ( iOS 15 . 0 , macOS 12 . 0 , * )
1213struct ContentView : View {
1314 // MARK: - Private Properties
1415
@@ -69,7 +70,7 @@ struct ContentView: View {
6970 }
7071 . font ( . footnote)
7172 . multilineTextAlignment ( . center)
72- . foregroundColor ( . red)
73+ . foregroundStyle ( . red)
7374 }
7475 . padding ( )
7576 }
@@ -120,6 +121,7 @@ struct ContentView: View {
120121
121122// MARK: - Preview Provider
122123
124+ @available ( iOS 15 . 0 , macOS 12 . 0 , * )
123125struct ContentView_Previews : PreviewProvider {
124126 static var previews : some View {
125127 ContentView ( )
Original file line number Diff line number Diff line change @@ -85,15 +85,15 @@ CachedAsyncImage(
8585 }
8686 .font (.footnote )
8787 .multilineTextAlignment (.center )
88- .foregroundColor (.red )
88+ .foregroundStyle (.red )
8989 }
9090 .padding ()
9191 }
9292 }
9393)
9494```
9595
96- ### Set image cache limit (optional)
96+ ### Set image cache limit if needed
9797** Note:** The default value is ` 0 ` , e.g. is no count limit and is no total cost limit.
9898
9999``` swift
Original file line number Diff line number Diff line change 1+ //
2+ // Extension + View.swift
3+ // CachedAsyncImage
4+ //
5+ // Created by Dmitry Kononchuk on 04.11.2023.
6+ // Copyright © 2023 Dmitry Kononchuk. All rights reserved.
7+ //
8+
9+ import SwiftUI
10+
11+ extension View {
12+ // MARK: - Public Methods
13+
14+ /// Used, e.g. to use the if #available statement.
15+ ///
16+ /// .conditional { view in
17+ /// if #available(iOS 16.0, *) {
18+ /// view
19+ /// .tint(cursorColor)
20+ /// } else {
21+ /// view
22+ /// .accentColor(cursorColor)
23+ /// }
24+ ///
25+ /// - Parameter transform: The transform to apply to the source `View`.
26+ ///
27+ /// - Returns: Either the original `View` or the modified `View`.
28+ func conditional< Content: View > (
29+ @ViewBuilder transform: ( Self ) -> Content
30+ ) -> Content {
31+ transform ( self )
32+ }
33+ }
Original file line number Diff line number Diff line change 11//
22// ResourcesManager.swift
3- // CachedAsyncImageTests
3+ // CachedAsyncImage
44//
55// Created by Dmitry Kononchuk on 18.06.2023.
66// Copyright © 2023 Dmitry Kononchuk. All rights reserved.
Original file line number Diff line number Diff line change @@ -172,7 +172,25 @@ struct CachedAsyncImage_Previews: PreviewProvider {
172172 }
173173 . font ( . footnote)
174174 . multilineTextAlignment ( . center)
175- . foregroundColor ( . red)
175+ . conditional { view in
176+ #if os(iOS)
177+ if #available( iOS 15 . 0 , * ) {
178+ view
179+ . foregroundStyle ( . red)
180+ } else {
181+ view
182+ . foregroundColor ( . red)
183+ }
184+ #elseif os(macOS)
185+ if #available( macOS 12 . 0 , * ) {
186+ view
187+ . foregroundStyle ( . red)
188+ } else {
189+ view
190+ . foregroundColor ( . red)
191+ }
192+ #endif
193+ }
176194 }
177195 . padding ( )
178196 }
You can’t perform that action at this time.
0 commit comments