OSDN Git Service

Futureを使用するようにした
authormasakih <masakih@users.sourceforge.jp>
Fri, 26 Jan 2018 12:43:21 +0000 (21:43 +0900)
committermasakih <masakih@users.sourceforge.jp>
Fri, 26 Jan 2018 12:43:21 +0000 (21:43 +0900)
KCD/ScreenshotListViewController.swift

index 6299de5..0f2c6dc 100644 (file)
@@ -195,11 +195,21 @@ final class ScreenshotListViewController: NSViewController {
     
     private func reloadData() {
         
-        screenshots.screenshots = ScreenshotLoader(screenshotSaveDirectoryURL).merge(screenshots: [])
-        
-        collectionView.selectionIndexPaths = [NSIndexPath(forItem: 0, inSection: 0) as IndexPath]
-        
-        reloadHandler?()
+        Promise<[ScreenshotInformation]>()
+            .complete {
+                Result(ScreenshotLoader(self.screenshotSaveDirectoryURL).merge(screenshots: []))
+            }
+            .future
+            .onSuccess { screenshots in
+                
+                DispatchQueue.main.async {
+                    self.screenshots.screenshots = screenshots
+                    
+                    self.collectionView.selectionIndexPaths = [NSIndexPath(forItem: 0, inSection: 0) as IndexPath]
+                    
+                    self.reloadHandler?()
+                }
+        }
     }
     
 }