Jelajahi Sumber

Services: make services properties nonoptional to only call Services() once and use dependency injection

Carola Nitz 7 tahun lalu
induk
melakukan
15ef3e63ea

+ 1 - 6
SharedSources/MediaDataSource.swift

@@ -14,7 +14,7 @@
 public class MediaDataSourceAndDelegate: NSObject, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
 
     private let cellPadding: CGFloat = 5.0
-    private var services: Services
+    private var services: Services!
     public weak var delegate: UICollectionViewDelegate?
 
     public convenience init(services: Services) {
@@ -22,11 +22,6 @@ public class MediaDataSourceAndDelegate: NSObject, UICollectionViewDataSource, U
         self.services = services
     }
 
-    public override init() {
-        self.services = Services()
-        super.init()
-    }
-
     public func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
         return Int(services.mediaDataSource.numberOfFiles())
     }

+ 1 - 2
Sources/MediaViewController.swift

@@ -19,7 +19,7 @@ import Foundation
 }
 
 public class VLCMediaViewController: UICollectionViewController, UISearchResultsUpdating, UISearchControllerDelegate {
-    private var services: Services
+    private var services: Services!
     private var mediaDatasourceAndDelegate: MediaDataSourceAndDelegate?
     private var searchController: UISearchController?
     private let searchDataSource = VLCLibrarySearchDisplayDataSource()
@@ -47,7 +47,6 @@ public class VLCMediaViewController: UICollectionViewController, UISearchResults
     }
 
     public override init(collectionViewLayout layout: UICollectionViewLayout) {
-        self.services = Services()
         super.init(collectionViewLayout: layout)
     }
 

+ 2 - 2
Sources/VLCTabBarCoordinator.swift

@@ -16,13 +16,13 @@ class VLCTabbarCooordinator: NSObject, VLCMediaViewControllerDelegate {
 
     private var childCoordinators: [NSObject] = []
     private var tabBarController: UITabBarController
-    private var services: Services
+    private var services: Services!
     private let displayController = VLCPlayerDisplayController()
 
     public init(tabBarController: UITabBarController, services: Services) {
         self.tabBarController = tabBarController
-        self.services = services
         super.init()
+        self.services = services
         NotificationCenter.default.addObserver(self, selector: #selector(updateTheme), name: .VLCThemeDidChangeNotification, object: nil)
     }