So I have a perplexing situation. I'm loading multiple SwiftUI AsyncImage
s according to spec (see code below). For some reason, my 1MB app has over 400+ MBs of documents & data. When I view the app's container, I can see that it is caused by a massive number of the images as .tmp files in the "tmp" folder all starting with the name "CFNetworkDownload". It seems that every time an image is loaded, it's stored in here, but does not delete. This makes the app get bigger every time it's opened. What can I do about this issue? Thanks so much! (P.S. I've tried to condense my code down as much as possible for readability, but there's a few files included because I'm not sure where the problem lies.)
Main app Swift file:
@main
struct MyApp: App {
let monitor = NWPathMonitor()
@State private var isConnected = true
var body: some Scene {
monitor.pathUpdateHandler = { path in
if path.status == .satisfied {
if !isConnected {
isConnected.toggle()
}
}
else {
if isConnected {
isConnected.toggle()
}
}
}
let queue = DispatchQueue(label: "Monitor")
monitor.start(queue: queue)
return WindowGroup {
isConnected ? AnyView(ContentView()) : AnyView(ContentViewFailed())
}
}
}
The ContentView
that's loaded inside the above WindowGroup
:
struct ContentView: View {
var body: some View {
TabView {
HomeView()
.tabItem {
Image(systemName: "house.fill")
Text("Home")
}
. . .
}
}
}
And finally, the HomeView
where the images are being loaded:
struct HomeView: View {
var body: some View {
let urlString = "https://www.example.com/Home.json"
if let url = URL(string: urlString) {
if let data = try? Data(contentsOf: url) {
do {
items = try JSONDecoder().decode([Item].self, from: data)
}
catch {
print(error)
}
}
}
return NavigationView {
List {
ScrollView {
VStack(alignment: .leading) {
ZStack {
VStack(alignment: .leading) {
Spacer()
HStack {
AsyncImage(url: URL(string: "https://www.example.com/images/example.png")) { image in
image
.resizable()
.aspectRatio(contentMode: .fill)
.shadow(color: Color(red: 0, green: 0, blue: 0, opacity: 0.25), radius: 1)
} placeholder: {
ProgressView()
.progressViewStyle(.circular)
}
.frame(width: 202, height: 100)
}
. . .
}
}
}
}
}
}
}
}
I really appreciate your time. Not sure if this could just be a bug with AsyncImage
itself.