Use a timer for observing files
@@ -296,12 +296,12 @@ class DocumentBrowserViewController: UIViewController, UICollectionViewDataSourc
collectionView.reloadData()
// Directory observer
- DispatchQueue.global(qos: .background).async {
+ _ = Timer.scheduledTimer(withTimeInterval: 0.5, repeats: false, block: { (timer) in
var files = self.scripts
- while true {
+
if self.stopObserver_ {
self.stopObserver_ = false
- break
+ timer.invalidate()
}
if files != self.scripts {
@@ -324,8 +324,7 @@ class DocumentBrowserViewController: UIViewController, UICollectionViewDataSourc
}
}
}
- }
- }
+ })
}
override func viewDidDisappear(_ animated: Bool) {
