From 1d05ccb7aa15648e18049ade1104d32a0ee0e2ae Mon Sep 17 00:00:00 2001 From: Khoa Pham Date: Wed, 4 Oct 2017 12:19:50 +0200 Subject: [PATCH] Inject configuration at init --- .../ImagePickerDemo/ViewController.swift | 3 +-- Source/ImagePickerController.swift | 16 +++++----------- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/Demo/ImagePickerDemo/ImagePickerDemo/ViewController.swift b/Demo/ImagePickerDemo/ImagePickerDemo/ViewController.swift index 7ba79ebf..a00c0f8e 100644 --- a/Demo/ImagePickerDemo/ImagePickerDemo/ViewController.swift +++ b/Demo/ImagePickerDemo/ImagePickerDemo/ViewController.swift @@ -42,8 +42,7 @@ class ViewController: UIViewController, ImagePickerDelegate { config.recordLocation = false config.allowVideoSelection = true - let imagePicker = ImagePickerController() - imagePicker.configuration = config + let imagePicker = ImagePickerController(configuration: config) imagePicker.delegate = self present(imagePicker, animated: true, completion: nil) diff --git a/Source/ImagePickerController.swift b/Source/ImagePickerController.swift index a0fb2421..d1b1a92c 100644 --- a/Source/ImagePickerController.swift +++ b/Source/ImagePickerController.swift @@ -11,7 +11,7 @@ import Photos open class ImagePickerController: UIViewController { - open var configuration = Configuration() + let configuration: Configuration struct GestureConstants { static let maximumHeight: CGFloat = 200 @@ -91,19 +91,13 @@ open class ImagePickerController: UIViewController { // MARK: - Initialization - public init(configuration: Configuration? = nil) { - if let configuration = configuration { - self.configuration = configuration - } + public required init(configuration: Configuration = Configuration()) { + self.configuration = configuration super.init(nibName: nil, bundle: nil) } - public override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) { - super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil) - } - - required public init?(coder aDecoder: NSCoder) { - super.init(coder: aDecoder) + public required init?(coder aDecoder: NSCoder) { + fatalError() } // MARK: - View lifecycle