             MyLog("SWAsset flush contentsOfDir failed (somethign is wrong)")
         }
 
-        let request = NSFetchRequest(entityName: "Asset")
-        do {
-            if let entities = try managedObjectContext.fetch(request) as? [NSManagedObject] {
-                MyLog("SNAsset flush count=\(entities.count)", level:1)
-                for entity in entities {
-                    managedObjectContext.delete(entity)
-                }
-                saveContext()
-            }
+        let request = NSFetchRequest<NSManagedObject>(entityName: "Asset")
+        do {
+            let entities = try managedObjectContext.fetch(request)
+            MyLog("SNAsset flush count=\(entities.count)", level:1)
+            for entity in entities {
+                managedObjectContext.delete(entity)
+            }
+            saveContext()
         } catch {
             MyLog("SWAsset flush fetch failed (something is wrong)")
         }

                entity.setValue(uuid, forKey: "uuid")
                entity.setValue(url.path, forKey: "url")
            } else {
                entity = results[0] as! NSManagedObject
                uuid = entity.value(forKey: "uuid") as! String
                //MyLog("SNAsset found entity=\(uuid)")
            }

    func reduce(_ limit:Int, amount:Int) {
        DispatchQueue.global( attributes: DispatchQueue.GlobalAttributes.qosDefault).async { () -> Void in
            let fm = FileManager.default
            let request = NSFetchRequest<NSManagedObject>(entityName: "Asset")
            request.sortDescriptors = [SortDescriptor(key: "lastModified", ascending: true)]
            request.fetchLimit = limit + amount // Number of items to fetch extra, to limit the nubmer of entities to delete for each reduce
            do {
                let entities = try self.managedObjectContext.fetch(request)
                if entities.count > limit {
                    for i in 0..<(entities.count-limit) {
                        let entity = entities[i]
                        if let date = entity.value(forKey: "lastModified") as? Date, let uuid = entity.value(forKey: "uuid") as? String {
                            MyLog("SNAsset reducing date=\(date), \(uuid)")
                            let urlLocal = try! self.urlFolder.appendingPathComponent(uuid)
                            do {
                                try fm.removeItem(at: urlLocal)
                            } catch {
                                MyLog("SWAsset reduce fail to remove (totally fine)")
                            }
                            self.managedObjectContext.delete(entity)
                        }
                    }
                }
