Skip to content

Instantly share code, notes, and snippets.

Avatar

Depa FranDepascuali

View GitHub Profile
View MyViewController.swift
public class MyViewController: UIViewController {
var viewModel: MyViewModel? {
willSet(maybeViewModel) {
if let _ = self.viewModel {
unbindViewModel()
}
}
didSet {
if isViewLoaded(), let viewModel = self.viewModel {
View ViewModelBindable.swift
public protocol ViewModelBindable: class {
typealias ViewModel
var viewModel: ViewModel? { get set }
func bindViewModel(viewModel: ViewModel)
func unbindViewModel(viewModel: ViewModel)
View ViewModelBindableExtension.swift
extension ViewModelBindable where Self: AnyObject {
public var viewModel: ViewModel? {
// store view model
}
}
View ViewModelBindable.swift
extension ViewModelBindable where Self: AnyObject {
public var viewModel: ViewModel? {
get {
return getAssociatedObject(self, key: &AssociatedKey)
}
set(newViewModel) {
if let viewModel = newViewModel {
View MyViewController.swift
public final class MyViewController: UIViewController {
// Your implementation
}
extension MyViewController: ViewModelBindable {
public func bindViewModel(viewModel: MyViewModel) {
// binding logic
}
View AssociatedObjects.swift
private var AssociatedKey: UInt = 1
private final class AssociatedObjectBox<T> {
let value: T
init(_ x: T) {
value = x
}
}
@FranDepascuali
FranDepascuali / CollapseViews.swift
Last active May 17, 2016
Collapse & uncollapse views
View CollapseViews.swift
extension UIView {
private var previousHeightConstraint: NSLayoutConstraint? {
return constraints.filterFirst { $0.firstAttribute == .Height }
}
}
/**
Collapse a view by adding/modifying constraint height.
View Fastlane.rb
# https://labs.kunstmaan.be/blog/ios-continuous-delivery-with-jenkins-and-fastlane?this-one-is-for-you-roderik
# Define the minimal Fastlane version
# fastlane_version "1.41.1"
# Use the iOS platform as default
default_platform :ios
# Define what to do for the iOS platform
platform :ios do
View logstash.conf
input {
syslog {
host => localhost
port => 5000
}
}
filter {
}
View Components.swift
protocol UIComponentType {
associatedtype Controller
associatedtype View
associatedtype ViewModel
func createController() -> Controller