浏览代码

Add providerSession singleton

Marino Faggiana 8 年之前
父节点
当前提交
8e28671109
共有 1 个文件被更改,包括 26 次插入6 次删除
  1. 26 6
      Picker/DocumentPickerViewController.swift

+ 26 - 6
Picker/DocumentPickerViewController.swift

@@ -27,9 +27,10 @@ class DocumentPickerViewController: UIDocumentPickerExtensionViewController, CCN
     
     // MARK: - Properties
     
+    var provider : providerSession?
+    
     var metadata : CCMetadata?
     var recordsTableMetadata : [TableMetadata]?
-    let dirGroup = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: capabilitiesGroups)
     
     var activeAccount : String?
     var activeUrl : String?
@@ -60,11 +61,7 @@ class DocumentPickerViewController: UIDocumentPickerExtensionViewController, CCN
     
     override func viewDidLoad() {
         
-        let pathDB = dirGroup?.appendingPathComponent(appDatabase).appendingPathComponent("cryptocloud")
-        print(pathDB!)
-        
-        MagicalRecord.setupCoreDataStackWithAutoMigratingSqliteStore(at: pathDB!)
-        MagicalRecord.setLoggingLevel(MagicalRecordLoggingLevel.off)
+        provider = providerSession.sharedInstance
         
         if let record = CCCoreData.getActiveAccount() {
             
@@ -188,3 +185,26 @@ class recordMetadataCell: UITableViewCell {
     @IBOutlet weak var FileName : UILabel!
 }
 
+// MARK: - Class providerSession
+
+class providerSession {
+    
+    class var sharedInstance : providerSession {
+        
+        struct Static {
+            
+            static let instance = providerSession()
+        }
+        
+        return Static.instance
+    }
+    
+    private init() {
+    
+        let dirGroup = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: capabilitiesGroups)
+        let pathDB = dirGroup?.appendingPathComponent(appDatabase).appendingPathComponent("cryptocloud")
+        
+        MagicalRecord.setupCoreDataStackWithAutoMigratingSqliteStore(at: pathDB!)
+        MagicalRecord.setLoggingLevel(MagicalRecordLoggingLevel.off)
+    }
+}