Skip to content

Instantly share code, notes, and snippets.

@LeonardoCardoso
Last active October 30, 2018 09:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LeonardoCardoso/f1854447c0cfec317f79b1bdb69f3f61 to your computer and use it in GitHub Desktop.
Save LeonardoCardoso/f1854447c0cfec317f79b1bdb69f3f61 to your computer and use it in GitHub Desktop.
RXMVVM Shell function

Usage

$ rxmvvm "AddressList" "LightPass" "Leonardo Cardoso" "1aim.com" .

  • $1 = Name of File
  • $2 = Name of Project
  • $3 = Name of Author
  • $4 = Website
  • $5 = Path
function rxmvvm {
# Usage = rxmvvm "AddressList" "LightPass" "Leonardo Cardoso" "1aim.com" .
# $1 = Name of File
# $2 = Name of Project
# $3 = Name of Author
# $4 = Website
# $5 = Path
mkdir $5/Extensions
mkdir $5/View\ Models
mkdir $5/Views
echo "//
// $1ViewController.swift
// $2
//
// Created by $3 on `date +%d/%m/%Y`.
// Copyright © 2017 $4. All rights reserved.
//
import UIKit
#if !RX_NO_MODULE
import RxSwift
import RxCocoa
#endif
final class $1ViewController: UIViewController {
// MARK: - Rx
private let bag = DisposeBag()
// MARK: - Properties
private var customView: $1View?
// MARK: - Lifecycle
override func viewDidLoad() { super.viewDidLoad() }
// MARK: - Functions
/**
Set up view controller
*/
static func setUp(viewModel: $1ViewModelType) -> $1ViewController {
let controller = $1ViewController()
controller.customView = .setUp(superview: controller.view)
controller.customView?.layout()
controller.configureBindings(viewModel: viewModel)
return controller
}
/**
Configure view model
*/
internal func configureBindings(viewModel: $1ViewModelType) {
// 2-way Binding
// Input
// Output
}
}" > $5/$1ViewController.swift
echo "//
// $1ViewController+UITableViewDelegate.swift
// $2
//
// Created by $3 on `date +%d/%m/%Y`.
// Copyright © 2017 $4. All rights reserved.
//
/// UITableViewDelegate
extension $1ViewController: UITableViewDelegate {
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 40
}
}" > $5/Extensions/$1ViewController+UITableViewDelegate.swift
echo "//
// $1ViewController+UITableViewDataSource.swift
// $2
//
// Created by $3 on `date +%d/%m/%Y`.
// Copyright © 2017 $4. All rights reserved.
//
/// UITableViewDataSource
extension $1ViewController: UITableViewDataSource {
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return String()
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 0
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
return UITableViewCell()
}
}" > $5/Extensions/$1ViewController+UITableViewDataSource.swift
echo "//
// $1ViewModel.swift
// $2
//
// Created by $3 on `date +%d/%m/%Y`.
// Copyright © 2017 $4. All rights reserved.
//
#if !RX_NO_MODULE
import RxSwift
import RxCocoa
#endif
protocol $1ViewModelType {
// MARK: - 2-way Binding
// MARK: - Input
// MARK: - Output
// MARK: - Flow
// MARK: - Initializers
init()
}
final class $1ViewModel: $1ViewModelType {
// MARK: - Properties
// MARK: - Rx
private let bag = DisposeBag()
// MARK: - 2-way Binding
// MARK: - Input
// MARK: - Output
// MARK: - Flow
// MARK: - Initializers
required init() {
}
}" > $5/View\ Models/$1ViewModel.swift
echo "//
// $1View.swift
// $2
//
// Created by $3 on `date +%d/%m/%Y`.
// Copyright © 2017 $4. All rights reserved.
//
import UIKit
import SnapKit
import Then
#if !RX_NO_MODULE
import RxSwift
import RxCocoa
#endif
final class $1View: UIView {
// MARK: - Properties
var wrapperView: UIView?
// MARK: - Functions
/**
Set up views.
*/
static func setUp(superview: UIView) -> $1View {
let view = $1View()
view.configureSubviews()
if let wrapperView = view.wrapperView { view.addSubview(wrapperView) }
superview.addSubview(view)
return view
}
/**
Configure subviews.
*/
func configureSubviews() {
wrapperView = UIView().then {
\$0.backgroundColor = .white
}
}
// Set up layout
func layout() {
snp.makeConstraints {
\$0.width.equalToSuperview()
\$0.height.equalToSuperview()
}
wrapperView?.snp.makeConstraints {
\$0.width.equalToSuperview()
\$0.height.equalToSuperview()
}
}
}" > $5/Views/$1View.swift
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment