Skip to content

Instantly share code, notes, and snippets.

:octocat:

Nathan Tannar nathantannar4

:octocat:
Block or report user

Report or block nathantannar4

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View IView.swift
import UIKit
protocol IView: AnyObject where Self: UIView {
func viewDidLoad()
func viewWillAppear(_ animated: Bool)
func viewDidAppear(_ animated: Bool)
func viewWillDisappear(_ animated: Bool)
func viewDidDisappear(_ animated: Bool)
}
View Controller.swift
import UIKit
class Controller<RootViewType: IView>: UIViewController {
var rootView: RootViewType! {
return view as? RootViewType
}
// MARK: - View Life Cycle
View FormCells.swift
import UIKit
class TextFieldCell: RowView<UILabel, TextField, UIView> {
var label: UILabel { return leftView }
var textField: TextField { return rightView }
}
class TextViewCell: RowView<UILabel, InputTextView, UIView> {
var label: UILabel { return leftView }
var textView: InputTextView { return rightView }
View RowView.swift
import UIKit
class RowView<LeftViewType: UIView, RightViewType: UIView, AccessoryViewType: UIView>: View {
let leftView = LeftViewType()
let rightView = RightViewType()
let accessoryView = AccessoryViewType()
override func viewDidLoad() {
super.viewDidLoad()
View CellWrappers.swift
import UIKit
protocol IReusableView: AnyObject where Self: UIView {
func prepareForReuse()
}
class TableViewCell<ViewType: IReusableView>: UITableViewCell {
let wrappedView = ViewType()
View ViewModelController.swift
import UIKit
class ViewModelController<ViewModelType: IViewModel>: UIViewController {
let viewModel: ViewModelType
required init(viewModel: ViewModelType) {
self.viewModel = viewModel
super.init(nibName: nil, bundle: nil)
}
@nathantannar4
nathantannar4 / Switch.swift
Created Dec 21, 2018
Re-Engineering Switch Outline
View Switch.swift
class Switch: UIControl {
var isOn: Bool
// Determines if the thumbLayer stretches on touchDown
var isStretchEnable: Bool
// Border of the trackLayer, this also determines the inset of the innerLayer
var borderWidth: CGFloat
@nathantannar4
nathantannar4 / Switch.swift
Created Dec 20, 2018
Re-Engineering UISwitch
View Switch.swift
//
// Switch.swift
// Re-Engineering UISwitch
//
// Created by Nathan Tannar on 15/12/18.
// Copyright © 2018 Nathan Tannar. All rights reserved.
//
import UIKit
@nathantannar4
nathantannar4 / Reflectable.swift
Created Dec 17, 2018
Generate JSON representation of values using the Mirror API
View Reflectable.swift
//
// Reflectable.swift
//
// Created by Nathan Tannar on 2018-12-04.
//
import Foundation
// Add this protocol to your `struct` or `class`
protocol Reflectable {
@nathantannar4
nathantannar4 / XCodeTemplateGenerator.swift
Created Sep 30, 2018
Autogenerate an Xcode TemplateInfo.plist file based on current project
View XCodeTemplateGenerator.swift
/*
XCodeTemplateGenerator.swift
Created by Nathan Tannar
Usage:
Run `swift XCodeTemplateGenerator.swift $SOURCE_FOLDER` where SOURCE_FOLDER is the root directory of your
XCode projects source code. A TemplateInfo.plist will be generated in the SOURCE_FOLDER allowing you
to copy the folder to your XCodes project template folder.
*/
You can’t perform that action at this time.