Created
August 6, 2026 23:50
-
-
Save StewartLynch/ef652d1b6c2eb5eca982fe3b559fcdfd to your computer and use it in GitHub Desktop.
ImageRequestMode enum and Selector for Video on AsyncImage for iOS 27
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Foundation | |
| enum ImageRequestMode: String, CaseIterable, Identifiable { | |
| case httpRules | |
| case cacheFirst | |
| case reload | |
| case cacheOnly | |
| var id: Self { self } | |
| var title: String { | |
| switch self { | |
| case .httpRules: "HTTP Rules" | |
| case .cacheFirst: "Cache First" | |
| case .reload: "Reload" | |
| case .cacheOnly: "Cache Only" | |
| } | |
| } | |
| var cachePolicy: URLRequest.CachePolicy { | |
| switch self { | |
| case .httpRules: .useProtocolCachePolicy | |
| case .cacheFirst: .returnCacheDataElseLoad | |
| case .reload: .reloadIgnoringLocalCacheData | |
| case .cacheOnly: .returnCacheDataDontLoad | |
| } | |
| } | |
| var explanation: String { | |
| switch self { | |
| case .httpRules: | |
| "Use normal HTTP freshness and validation rules." | |
| case .cacheFirst: | |
| "Use cached data when available; otherwise load it." | |
| case .reload: | |
| "Ignore locally cached data and load from the server." | |
| case .cacheOnly: | |
| "Use cached data only and fail when it is unavailable." | |
| } | |
| } | |
| } | |
| /* | |
| private struct CachePolicySelector: View { | |
| @Binding var requestMode: ImageRequestMode | |
| var body: some View { | |
| VStack(alignment: .leading, spacing: 4) { | |
| HStack { | |
| Text("Request policy") | |
| .font(.headline) | |
| Spacer() | |
| Picker("Request policy", selection: $requestMode) { | |
| ForEach(ImageRequestMode.allCases) { mode in | |
| Text(mode.title) | |
| .tag(mode) | |
| } | |
| } | |
| .pickerStyle(.menu) | |
| } | |
| Text(requestMode.explanation) | |
| .font(.caption) | |
| .foregroundStyle(.secondary) | |
| } | |
| .padding(.horizontal) | |
| .padding(.bottom, 8) | |
| } | |
| } | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment