title: How do I show an activity indicator in swiftUI while my CoreData is being fetched?
body: <p>When I create or update a CoreData entry in swiftUI it takes a moment for my app to update. During this time I'd like provide some visual feedback in the form of an Activity Indicator. Following <a href="https://medium.com/@tianna_lewis05/cracking-swiftui-implementing-uiactivityindicator-3e1402d5677f" rel="nofollow noreferrer">this tutorial</a> I can get the loading view to appear but how do I get it to disappear once it's Fetched my updated entries? </p>
  
  <p><strong>Content View</strong></p>
  
  <pre><code>import SwiftUI
  import CoreData
  
  struct ContentView: View {
  
      @FetchRequest(entity: DiaryItem.entity(), sortDescriptors: [
          NSSortDescriptor(keyPath: \DiaryItem.createdAt, ascending: false),
      ]) var diaryItems : FetchedResults&lt;DiaryItem&gt;
  
      var body: some View {
          LoadingView(isShowing: .constant(true)) {
              HStack {
                  ForEach(self.diaryItems) { diaryItem in
                      DiaryItemView(
                          title: diaryItem.title!,
                          createdAt: "\(diaryItem.createdAt!)",
                          diaryItem: diaryItem
                      )
                  }
              }
          }
      }
  }
  
  struct ActivityIndicator: UIViewRepresentable {
  
      @Binding var isAnimating: Bool
      let style: UIActivityIndicatorView.Style
  
      func makeUIView(context: UIViewRepresentableContext&lt;ActivityIndicator&gt;) -&gt; UIActivityIndicatorView {
          return UIActivityIndicatorView(style: style)
      }
  
      func updateUIView(_ uiView: UIActivityIndicatorView, context: UIViewRepresentableContext&lt;ActivityIndicator&gt;) {
          isAnimating ? uiView.startAnimating() : uiView.stopAnimating()
      }
  }
  </code></pre>
  
  <p><strong>Loading View</strong></p>
  
  <pre><code>struct LoadingView&lt;Content&gt;: View where Content: View {
  
      @Binding var isShowing: Bool
      var content: () -&gt; Content
  
      var body: some View {
          GeometryReader { geometry in
              ZStack(alignment: .center) {
  
                  self.content()
                      .disabled(self.isShowing)
                      .blur(radius: self.isShowing ? 3 : 0)
  
                  VStack {
                      ActivityIndicator(isAnimating: .constant(true), style: .large)
                  }
                  .frame(width: geometry.size.width / 2,
                         height: geometry.size.height / 5)
                  .background(Color.secondary.colorInvert())
                  .foregroundColor(Color.primary)
                  .cornerRadius(20)
                  .opacity(self.isShowing ? 1 : 0)
              }
          }
      }
  }
  </code></pre>