This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Gallery+Rx.swift | |
// Ctzen | |
// | |
// Created by Daniel Marulanda on 2/13/17. | |
// Copyright © 2017 Ctzen, Inc. All rights reserved. | |
//swiftlint:disable force_cast | |
import Foundation | |
import RxSwift |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension UIControl { | |
static func valuePublic<T, ControlType: UIControl>(_ control: ControlType, getter: @escaping (ControlType) -> T, setter: @escaping (ControlType, T) -> Void) -> ControlProperty<T> { | |
let values: Observable<T> = Observable.deferred { [weak control] in | |
guard let existingSelf = control else { | |
return Observable.empty() | |
} | |
return (existingSelf as UIControl).rx.controlEvent([.allEditingEvents, .valueChanged]) | |
.flatMap { _ in | |
return control.map { Observable.just(getter($0)) } ?? Observable.empty() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Extension that allows format numbers into words -> 1.000 = 1K 1.500 -> 1.5K 1.000.000 -> 1M. | |
//Usage: myInt.abbreviateNumber() | |
extension Int{ | |
func abbreviateNumber() -> String { | |
if self < 1000 { | |
return "\(self)" | |
} | |
if self < 1000000 { |