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 UIViewController { | |
| func embed(_ vc: UIViewController, in _containerView: UIView? = nil) { | |
| let containerView: UIView = _containerView ?? view // Use the whole view if no container view is provided. | |
| containerView.addSubview(vc.view) | |
| NSLayoutConstraint.activate([ | |
| vc.view.leadingAnchor.constraint(equalTo: containerView.leadingAnchor, constant: 0), | |
| vc.view.trailingAnchor.constraint(equalTo: containerView.trailingAnchor, constant: 0), | |
| vc.view.topAnchor.constraint(equalTo: containerView.topAnchor, constant: 0), | |
| vc.view.bottomAnchor.constraint(equalTo: containerView.bottomAnchor, constant: 0) | |
| ]) |
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 UIView { | |
| func superview<T>(of type: T.Type) -> T? { | |
| return superview as? T ?? superview.flatMap { $0.superview(of: type) } | |
| } | |
| } | |
| // Example usage: | |
| func textFieldDidBeginEditing(_ textField: UITextField) { | |
| // Get the cell containing the textfield. |
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 NSAttributedString { | |
| func highlighting(_ substring: String, using color: UIColor) -> NSAttributedString { | |
| let attributedString = NSMutableAttributedString(attributedString: self) | |
| attributedString.addAttribute(.foregroundColor, value: color, range: (self.string as NSString).range(of: substring)) | |
| return attributedString | |
| } | |
| } | |
| // Usage: |
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 Array { | |
| subscript(indexPath: IndexPath) -> Element { | |
| self[indexPath.row] | |
| } | |
| } |
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
| import Foundation | |
| extension Array { | |
| subscript(indexPath: IndexPath) -> Element { | |
| self[indexPath.row] | |
| } | |
| } |
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 UIViewController { | |
| func presentAsSheet(_ vc: UIViewController, height: CGFloat) { | |
| let presentationController = SheetModalPresentationController(presentedViewController: vc, | |
| presenting: self, | |
| height: height) | |
| vc.transitioningDelegate = presentationController | |
| vc.modalPresentationStyle = .custom | |
| present(vc, animated: true) | |
| } |
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
| let presentationController = SheetModalPresentationController(presentedViewController: vc, | |
| presenting: self, | |
| height: height) | |
| vc.transitioningDelegate = presentationController | |
| vc.modalPresentationStyle = .custom | |
| present(vc, animated: true) |
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
| interactor.completionSpeed = max(1, velocity / (gestureView.frame.height * (1 / interactor.duration))) |
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
| import UIKit | |
| extension UIView { | |
| var allSubviews: [UIView] { | |
| subviews + subviews.flatMap { $0.allSubviews } | |
| } | |
| func firstSubview<T: UIView>(of type: T.Type) -> T? { | |
| allSubviews.first { $0 is T } as? T |