diff --git a/Demo/Sources/Settings/SettingsView.swift b/Demo/Sources/Settings/SettingsView.swift index 66bd0e874..d1407bfbf 100644 --- a/Demo/Sources/Settings/SettingsView.swift +++ b/Demo/Sources/Settings/SettingsView.swift @@ -8,6 +8,35 @@ import AVFoundation import Player import SwiftUI +private struct UrlCacheView: View { + @State private var urlCacheSize: String = "" + + var body: some View { + HStack { + Button("Clear URL cache", action: clearUrlCache) +#if os(iOS) + .buttonStyle(.borderless) +#endif + Spacer() + Text(urlCacheSize) + .font(.footnote) + .foregroundColor(.red) + } + .onAppear { + updateCacheSize() + } + } + + private func updateCacheSize() { + urlCacheSize = ByteCountFormatter.string(fromByteCount: Int64(URLCache.shared.currentDiskUsage), countStyle: .binary) + } + + private func clearUrlCache() { + URLCache.shared.removeAllCachedResponses() + updateCacheSize() + } +} + struct SettingsView: View { @AppStorage(UserDefaults.presenterModeEnabledKey) private var isPresenterModeEnabled = false @@ -104,7 +133,7 @@ struct SettingsView: View { private func debuggingSection() -> some View { Section { Button("Simulate memory warning", action: simulateMemoryWarning) - Button("Clear URL cache", action: clearUrlCache) + UrlCacheView() } header: { Text("Debugging") } footer: { @@ -130,10 +159,6 @@ struct SettingsView: View { private func simulateMemoryWarning() { UIApplication.shared.perform(Selector(("_performMemoryWarning"))) } - - private func clearUrlCache() { - URLCache.shared.removeAllCachedResponses() - } } #Preview {