This file contains 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
import RxSwift | |
extension ObservableType { | |
typealias EmptyHandler = () -> Void | |
func onNext(_ onNext: @escaping (E) -> Void) -> Observable<E> { | |
return `do`(onNext: onNext) | |
} | |
This file contains 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
func benchmark(repeatCount: Int = 1, name: String? = nil, closure: () -> Void) { | |
let d = CACurrentMediaTime() | |
for _ in 0..<repeatCount { | |
closure() | |
} | |
let d1 = CACurrentMediaTime() - d | |
print("Benchmark of \(name ?? "closure") took \(d1) seconds") | |
} |
This file contains 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
#if os(iOS) | |
import UIKit | |
#elseif os(OSX) | |
import AppKit | |
#endif | |
fileprivate struct ColorComponents { | |
let first: CGFloat | |
let second: CGFloat |
This file contains 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
func &=(lhs: inout Bool, rhs: @autoclosure () -> Bool) { | |
lhs = lhs && rhs() | |
} | |
infix operator ||=: AssignmentPrecedence | |
func ||=(lhs: inout Bool, rhs: @autoclosure () -> Bool) { | |
lhs = lhs || rhs() | |
} |
This file contains 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
import UIKit | |
extension UIView { | |
func вжух() { | |
setNeedsLayout() | |
layoutIfNeeded() | |
} | |
} |
This file contains 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
import UIKit | |
extension UITableView { | |
func dequeueReusableCell<T: UITableViewCell>() -> T { | |
return dequeueReusableCell(withIdentifier: NSStringFromClass(T.self)) as! T | |
} | |
} | |
//using: let cell: ExampleTableViewCell = tableView.dequeueReusableCell() |
This file contains 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
import UIKit | |
extension UIView { | |
func round(with radius: CGFloat, corners: UIRectCorner) { | |
let roundedPath = UIBezierPath(roundedRect: bounds, | |
byRoundingCorners: corners, | |
cornerRadii: CGSize(width: radius, height: radius)) | |
let maskLayer = CAShapeLayer() | |
maskLayer.path = roundedPath.cgPath |
NewerOlder