---
title: "Discussion on \"Image Caching in SwiftUI\" | Hashnode"
description: "Discussion on \"Image Caching in SwiftUI\". Caching images is an important technique for optimizing the performance of your SwiftUI app. When you load an image, it can take time to fetch it from a remote server or read it from disk. By caching the image, you can avoid repeating this time-consu..."
url: "https://hashnode.com/posts/image-caching-in-swiftui/643f6feed57814777ce8cebf"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Image Caching in SwiftUI](https://xavier7t.com/image-caching-in-swiftui?utm_source=hashnode&utm_medium=feed)

Caching images is an important technique for optimizing the performance of your SwiftUI app. When you load an image, it can take time to fetch it from a remote server or read it from disk. By caching the image, you can avoid repeating this time-consu...

Apr 19, 2023 · 3 min read · xavier7t.com  
Read the article

-   [#ios](https://hashnode.com/tag/ios)
-   [#swift](https://hashnode.com/tag/swift)
-   [#swiftui](https://hashnode.com/tag/swiftui)
-   [#iosdevx](https://hashnode.com/tag/iosdevx)
-   [#imagecaching](https://hashnode.com/tag/imagecaching)

## Written by

[Xavier](https://hashnode.com/@xavier7t)

@xavier7t · Toronto, ON, CAN

  
[View profile](https://hashnode.com/@xavier7t)

iOS Developer

iOS developer from Toronto, ON, CAN

## Responses 2

Markdown supported · ⌘↵ to post

[Viraj Shah](https://hashnode.com/@youngvz)

[Oct 26, 2023](https://hashnode.com/posts/image-caching-in-swiftui/643f6feed57814777ce8cebf/comment/6539c73d8a6f01795363e2aa)

Loved this implementation. Simple concept that is easy to integrate without having to add a lot of code.

[Jesse Lindberg](https://hashnode.com/@lndbrg)

[Sep 26, 2023](https://hashnode.com/posts/image-caching-in-swiftui/643f6feed57814777ce8cebf/comment/651271c20e30bf4ef5d7d49c)

Hey Xavier! Good stuff, thanks for the article.

I was wondering, how would you handle uploading a local file and having it immediately reflect in the UI? Because the Image views use instances of ImageLoader to load the image, which makes it hard to access those instances and change the image.

Let's say I have photosPicker, from where I get the image data from PhotosPickerItem for a newly uploaded image. But I can't wrap my head around how I'd get that new data into the ImageLoader instances that are already being used (and now with the old, outdated image) in my views.

[Abdurahmon Jamoliddinov](https://hashnode.com/@abdudev)

[Jan 9, 2024](https://hashnode.com/posts/image-caching-in-swiftui/643f6feed57814777ce8cebf/comment/651271c20e30bf4ef5d7d49c#reply-659ce10fb80581bc195df33d)

I used fileImporter and got local URL to image then I am getting data for URL like the following

let \_ = fileUrl.startAccessingSecurityScopedResource() let file = try Data(contentsOf: fileUrl) fileUrl.stopAccessingSecurityScopedResource()

then I am uploading the data to my server and getting URL and displaying that in my ImageView

if that helps
