Skip to content

Commit

Permalink
Allow to customize storage to be used without actually creating Memor…
Browse files Browse the repository at this point in the history
…yStorage every time.
  • Loading branch information
DenTelezhkin committed Apr 7, 2019
1 parent 0545b8b commit b008d05
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 16 deletions.
13 changes: 10 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,16 @@ All notable changes to this project will be documented in this file.

# Next

* Added [documentation](https://dentelezhkin.github.io/DTTableViewManager)
* Added support fort Xcode 10.2 and Swift 5
* Dropped support for Xcode 9 and Swift 3
### Added

* Convenience constructor for `DTTableViewManager` object: `init(storage:)` that allows to create it's instance without initializing `MemoryStorage`.
* Static variable `defaultStorage` on `DTTableViewManager` that allows to configure which `Storage` class is used by default.
* [Documentation](https://dentelezhkin.github.io/DTTableViewManager)
* Support for Xcode 10.2 and Swift 5

### Removed

* Support for Xcode 9 and Swift 3

## [6.4.0](https://github.com/DenTelezhkin/DTTableViewManager/releases/tag/6.4.0)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ class AutoDiffSearchViewController: UIViewController, DTTableViewManageable, UIS
override func viewDidLoad() {
super.viewDidLoad()

manager = DTTableViewManager(storage: storage)
manager.register(StringCell.self)
manager.storage = storage
searchController.searchResultsUpdater = self
searchController.searchBar.sizeToFit()
tableView.tableHeaderView = searchController.searchBar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ class CoreDataSearchViewController: UIViewController, DTTableViewManageable {

override func viewDidLoad() {
super.viewDidLoad()
manager = DTTableViewManager(storage: CoreDataStorage(fetchedResultsController: fetchResultsController))
manager.register(BankCell.self)
manager.storage = CoreDataStorage(fetchedResultsController: fetchResultsController)
manager.tableViewUpdater?.didUpdateContent = { [weak self] _ in
self?.tableView.isHidden = self?.tableView.numberOfSections == 0
}
Expand Down
23 changes: 13 additions & 10 deletions Source/DTTableViewManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,6 @@ extension DTTableViewOptionalManageable {
/// - SeeAlso: `startManagingWithDelegate:`
open class DTTableViewManager {

/// Creates `DTTableViewManager`. Usually you don't need to call this method directly, as `manager` property on `DTTableViewManageable` instance is filled automatically.
public init() {}

/// Stores all configuration options for `DTTableViewManager`.
/// - SeeAlso: `TableViewConfiguration`.
open var configuration = TableViewConfiguration()
Expand All @@ -112,7 +109,7 @@ open class DTTableViewManager {
open var isManagingTableView : Bool {
return tableView != nil
}

/// Factory for creating cells and views for UITableView
final lazy var viewFactory: TableViewFactory = {
precondition(self.isManagingTableView, "Please call manager.startManagingWithDelegate(self) before calling any other DTTableViewManager methods")
Expand Down Expand Up @@ -148,12 +145,7 @@ open class DTTableViewManager {
/// - Note: When setting custom storage for this property, it will be automatically configured for using with UITableView and it's delegate will be set to `DTTableViewManager` instance.
/// - Note: Previous storage `delegate` property will be nilled out to avoid collisions.
/// - SeeAlso: `MemoryStorage`, `CoreDataStorage`, `RealmStorage`.
open var storage : Storage = {
let storage = MemoryStorage()
storage.configureForTableViewUsage()
return storage
}()
{
open var storage : Storage {
willSet {
storage.delegate = nil
}
Expand Down Expand Up @@ -217,6 +209,17 @@ open class DTTableViewManager {
}
#endif

/// Storage construction block, used by `DTTableViewManager` when it's created. Returns `MemoryStorage` by default.
public static var defaultStorage: () -> Storage = { MemoryStorage() }

/// Creates `DTTableViewManager`. Usually you don't need to call this method directly, as `manager` property on `DTTableViewManageable` instance is filled automatically. `DTTableViewManager.defaultStorage` closure is used to determine which `Storage` would be used by default.
///
/// - Parameter storage: storage class to be used
public init(storage: Storage = DTTableViewManager.defaultStorage()) {
(storage as? BaseStorage)?.configureForTableViewUsage()
self.storage = storage
}

/// Starts managing `UITableView`.
///
/// Call this method before calling any of `DTTableViewManager` methods.
Expand Down
5 changes: 4 additions & 1 deletion fastlane/Fastfile
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,15 @@ lane :release do |params|
changelog.gsub!(/# Next/, "# Next\n\n## [#{version}](https://github.com/DenTelezhkin/DTTableViewManager/releases/tag/#{version})")
File.open(changelog_filename, 'w') { |file| file.puts changelog }

puts "Updating docs"
sh "bundle exec jazzy"

puts "Comitting, tagging, and pushing."
message = "Releasing version #{version}."
sh "git commit -am '#{message}'"
sh "git tag #{version} -m '#{message}'"
sh "git push --follow-tags"

puts "Updating Specs repo"
sh "bundle exec pod repo update"

Expand Down

0 comments on commit b008d05

Please sign in to comment.