Skip to content

Instantly share code, notes, and snippets.

View gracietti's full-sized avatar

Marcelo Gracietti gracietti

View GitHub Profile
@gracietti
gracietti / ReusableView.swift
Created April 5, 2017 00:50
ReusableView extension
import Foundation
import UIKit
protocol ReusableView: class {}
extension ReusableView {
static var reuseIdentifier: String {
return String(describing: self)
}
@gracietti
gracietti / UIViewController.swift
Created April 5, 2017 00:52
Make all ViewControllers extend ReusableView
import Foundation
import UIKit
extension UIViewController: ReusableView { }
@gracietti
gracietti / UIStoryboard.swift
Created April 5, 2017 00:54
Add this extension to the Storyboard
import Foundation
import UIKit
extension UIStoryboard {
func instantiateViewController<T: UIViewController>() -> T where T: ReusableView {
return instantiateViewController(withIdentifier: T.reuseIdentifier) as! T
}
}
@gracietti
gracietti / FileRouter.swift
Created April 5, 2017 00:58
Keep init code on router
class FileRouter {
// MARK: Properties
weak var view: UIViewController?
// MARK: Static methods
static func setupModule() -> FileViewController {
let viewController = UIStoryboard(name: FileViewController.storyboardName).instantiateViewController() as! FileViewController
@gracietti
gracietti / Delegates.swift
Created April 5, 2017 03:38
Sending messages with delegates
// 1. Declare which messages can be sent to the delegate
// File ProductScreenDelegate.swift
protocol ProductScreenDelegate {
//Add arguments if you need to send some information
func onProductScreenDismissed()
func onProductSelected(_ product: Product?)
}
@gracietti
gracietti / DelegatesSend.swift
Created April 5, 2017 04:10
Sending messages with delegates
// 1. Declare which messages can be sent to the delegate
// File ProductCategoriesCoreDelegate.swift
protocol ProductCategoriesCoreDelegate: class {
//Add arguments if you need to send some information
func setupSubmodules(with product: Product)
}
// 2. Create a delegate to send him a message
@gracietti
gracietti / MainSearchInteractor.swift
Last active April 7, 2017 14:49
Example of Interactor
class MainSearchInteractor {
// Properties
weak var output: MainSearchInteractorOutput?
var apiDataManager = ProfileApiDataManager()
var localDataManager = ProfileLocalDataManager()
}
extension MainSearchInteractor: MainSearchUseCase {
@gracietti
gracietti / MainSearchContract.swift
Last active April 7, 2017 14:54
Example of Contract
import Foundation
protocol MainSearchView: BaseView {
func showCustomError(_ message: String?)
func updateVisibility(onSearchController willBeActive: Bool)
func showSearchResult(_ products: [Product]?, shouldAppend: Bool)
}
protocol MainSearchPresentation: class {
import Foundation
import UIKit
class KeyboardController: NSObject {
var viewController: UIViewController
var constraint: NSLayoutConstraint
var isKeyboardHidden: Bool {
return constraint.constant == 0
}
@gracietti
gracietti / Event
Created June 6, 2017 13:55
Example of an Entity with computed properties
import Foundation
import RealmSwift
import ObjectMapper
import ObjectMapper_Realm
class Event: Object, Mappable, Identifiable, RandomizePlaceholder, TrackableEntity {
dynamic var id: Int = 0
fileprivate dynamic var stringType: String = ""
fileprivate dynamic var title = ""