Is there a way to cache images in swiftui in WidgetKit?

Viewed 63

I realized you can display images in widget like this stack overflow answer. https://stackoverflow.com/a/64163384/13476728

However, I was wondering if this keeps calling the url every time when it refreshes through timelineprovider? if it does, how do i store the image through cache and display it so it doesnt call the url every time. (In this example "https://www.test.com")

Group {
        let tempUrl = URL(string: "https://www.test.com")!
           if let url = tempUrl, let imageData = try? Data(contentsOf: tempUrl),
              
                
             let uiImage = UIImage(data: imageData) {
             if(uiImage != nil){
             Image(uiImage: uiImage)
               .resizable()
             } else{
               black
             }
            }
                      }
0 Answers
Related