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 |
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 вжух() { | |
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
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
#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 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
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
import AppKit | |
extension NSViewController { | |
static func load<T>() -> T where T: NSViewController { | |
return T(nibName: T.className(), bundle: nil)! | |
} | |
} | |
//Usage: | |
//let viewController: LoginViewController = .load() |
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
disabled_rules: | |
- trailing_whitespace | |
excluded: | |
- Carthage/ | |
force_try: warning | |
force_cast: warning | |
line_length: 180 | |
colon: | |
apply_to_dictionaries: false |
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
protocol KeyboardNotificationObserver { | |
typealias Selectors = (show: Selector, hide: Selector) | |
func addKeyboardWillChangeObservers(with selectors: Selectors) | |
func removeKeyboardWillChangeObservers() | |
func addKeyboardDidChangeObservers(with selectors: Selectors) | |
func removeKeyboardDidChangeObservers() | |
} |
OlderNewer