All Projects → cosmicfools → ModuleServices

cosmicfools / ModuleServices

Licence: MIT license
Reusable ViewController with TableView, split in Sections (called here modules) that help you to develop faster in Swift

Programming Languages

swift
15916 projects
ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to ModuleServices

felix-atomos
Apache Felix Atomos
Stars: ✭ 32 (+52.38%)
Mutual labels:  modules
css-flat-loader
CSS Flat 一种CSS模块化解决方案
Stars: ✭ 16 (-23.81%)
Mutual labels:  modules
UITableView-Examples
UITableView の設置例まとめ for Objective-C
Stars: ✭ 13 (-38.1%)
Mutual labels:  uitableview
monorepo-split-github-action
Github Action for Monorepo Split
Stars: ✭ 56 (+166.67%)
Mutual labels:  split
bymattlee-11ty-starter
A starter boilerplate powered by 11ty, Sanity, Gulp, Tailwind CSS, rollup.js, Alpine.js and Highway.
Stars: ✭ 27 (+28.57%)
Mutual labels:  modules
GenericCells
Creating generic UITableViewCells and UICollectionViewCells instead of subclasses.
Stars: ✭ 81 (+285.71%)
Mutual labels:  uitableview
BJOTPViewController
Entering OTP made simpler.
Stars: ✭ 42 (+100%)
Mutual labels:  viewcontroller
nuxt-modules
AX2's Nuxt modules
Stars: ✭ 30 (+42.86%)
Mutual labels:  modules
ote
ote updates a packages' go.mod file with a comment next to all dependencies that are test dependencies; identifying them as such.
Stars: ✭ 25 (+19.05%)
Mutual labels:  modules
FunFacts
FunFacts is an example of Modular architecture
Stars: ✭ 42 (+100%)
Mutual labels:  modules
Router-deprecated
🛣 Simple Navigation for iOS - ⚠️ Deprecated
Stars: ✭ 458 (+2080.95%)
Mutual labels:  viewcontroller
TinyCoordinator
The Swift version of ThinningCoordinator focus on lighter view controllers.
Stars: ✭ 18 (-14.29%)
Mutual labels:  uitableview
patchify.py
A library that helps you split image into small, overlappable patches, and merge patches into original image.
Stars: ✭ 102 (+385.71%)
Mutual labels:  split
YAAdapterTableViewWithResponderChain
No description or website provided.
Stars: ✭ 15 (-28.57%)
Mutual labels:  uitableview
SHTransition
SHTransition is a simple library for viewcontroller transition animation in swift.
Stars: ✭ 35 (+66.67%)
Mutual labels:  viewcontroller
react-client
React JS SDK client for Split Software
Stars: ✭ 23 (+9.52%)
Mutual labels:  split
icingaweb2-module-vspheredb
The easiest way to monitor a VMware vSphere environment.
Stars: ✭ 88 (+319.05%)
Mutual labels:  modules
uitableview-prefetching
Demonstrating how to use prefetching with UITableView
Stars: ✭ 17 (-19.05%)
Mutual labels:  uitableview
react-typewriter-js
Simple vanilla JS script to simulate text typewriting effect.
Stars: ✭ 18 (-14.29%)
Mutual labels:  split
URParallaxScrollAnimator
Show an animation as far as moved scroll while scrolling at the scroll view
Stars: ✭ 34 (+61.9%)
Mutual labels:  uitableview

ModuleServices

CI Version License Platform Readme Score

Requirements

Is valid for iOS 12 and higher. Requires Swift 5.5 and XCode 11.0 or higher.

Installation

Swift Package Manager

You can install CombinationGenerator via Swift Package Manager by adding the following line to your Package.swift:

import PackageDescription

let package = Package(
    [...]
    dependencies: [
        .Package(name: "ModuleServices", url: "https://github.com/cosmicfools/ModuleServices.git", .branch("master"))
    ]
)

Cocoapods

You can install CombinationGenerator via Cocoapods by adding the following line to your Podfile:

pod 'ModuleServices'

How to use it

ModuleServices basically is a pack of tools that is helping you to develop faster. This libabry is so useful for those UIViewControllers that are based in UITableView. The main concept in this libary is, a Module means a Section in a UITableView, so there is a subclass of UIViewController called ModulesViewController that manage all modules.

A Module is a like and mini UIViewController, should be able to work it self.

Basically a ModulesViewController has an array of TableSectionModules.

Sometimes an example is easier to understand than 1000 words.. so, we have an additionaly repository full of examples: Module-examples

Let me give it a try

1. Create a Module

You need to create a subclass of TableSectionModule

class FirstSectionModule: TableSectionModule {}

2. Override the needed methods in the Module

There are a lot of methods that could be override. The most usuals are:

  • Registration of UITableViewCell/UITableViewHeaderFooterView with Class/Nib
override func registerClassForCells() -> [AnyClass]
override func registerClassForHeadersFooters() -> [AnyClass]
override func registerNibsForCells() -> [AnyClass] 
override func registerNibsForHeadersFooters() -> [AnyClass] 
  • Creation of rows, this is the like the data source of the UITableView
override func createRows()
  • Dequeue and configure of the UITableViewCell
override func tableView(_ tableView: UITableView, cellForRowAtIndexPath indexPath: IndexPath) -> UITableViewCell
  • Rest of method that could be override You can override basically the same method that the UITableViewDelegate and UITableViewDataSource offer.

  • Obviously you will need to create&configure all the UITableViewCells that the Module would contains.

Example of TableSectionModule with methods

import ModuleServices

class FirstSectionModule: TableSectionModule {
    override func registerNibsForCells() -> [AnyClass] {
        return super.registerNibsForCells() + [
            Example1TableViewCell.classForCoder(),
        ]
    }
    
    override func registerClassForCells() -> [AnyClass] {
        super.registerClassForCells() + [UITableViewCell.classForCoder()]
    }
    
    override func createRows() {
        super.createRows()
        
        rows.append(String(describing: Example1TableViewCell.self))
        rows.append(String(describing: UITableViewCell.self))
    }
    
    override func tableView(_ tableView: UITableView, cellForRowAtIndexPath indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: className, for: indexPath)
        
        let className = rows[(indexPath as NSIndexPath).row] as! String
        //Addtional configuration for the cell
        switch className {
        case String(describing: UITableViewCell.self):
            cell.textLabel?.text = "A tottally native cell"
            break
        default:
            break
        }
        
        return cell
    }
    
    override func tableView(_ tableView: UITableView, heightForRowAtIndexPath indexPath: IndexPath) -> CGFloat {
        return 44.0
}



3. Create a ModulesViewController

You need to create a subclass of ModulesViewController

class MyViewController: ModulesViewController {}

4. Override the needed methods in the ViewController

The methods to be override in the ModulesViewController are less than on the Modules. Usually is just needed to override the createModules

override func createModules()

This method will add all the modules that the view controller could have. Like this example:

override func createModules() {
        super.createModules()
        
        appendModule(FirstSectionModule(tableView: tableView!))
    }

Example of ModulesViewController with methods

import ModuleServices

class MyViewController: ModulesViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        tableView?.rowHeight = UITableViewAutomaticDimension
        tableView?.estimatedRowHeight = 44
        
        tableView?.tableFooterView = UIView()
    }

    override func createModules() {
        super.createModules()
        
        appendModule(FirstSectionModule(tableView: tableView!))
    }

}




As could appreciate this is a very good approach to avoid masive view controllers. The main idea is to split responsabilities.

  • A ModulesViewController will manage (add/remove) TableSectionModule
  • A TableSectionModule will manage the cells that the section itself will contains
  • A TableSectionModule could contain enough logic & responsability how to make it fully work that section of the UITableView



Enjoy and be module my developer! :godmode:



Author

Francisco Javier Trujillo Mata, [email protected]

License

ModuleServices is available under the MIT license. See the LICENSE file for more info.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].