title: How to run for loop in background thread swift
body: <p>i am using for loop to iterate photos and adding it to core data but it blocks UI thread while in process I am using </p>
  
  <pre><code>self.fetchResult = PHAsset.fetchAssets(with: .image, options: allPhotosOptions)
  
  DispatchQueue.main.async { }
  
  for i in 0 ..&lt; self.fetchResult.count {
      GenericCoreData.saveEntity("Details")
  }
  </code></pre>