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
class TabBarController: UITabBarController { | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
/// 1 - Set view Controllers using `TabBarViewModel` | |
/// 2 - This iteration will create a master veiw controller embedded in a navigation controller for each tab. | |
/// 3 - `inSplitViewControllerIfSupported` is a `UINavigationController` extension method that will embed it in a `UISplitViewController` if supported. | |
/// we will see the implementation later. | |
viewControllers = TabBarViewModel.allCases.map { NavigationController(rootViewController: $0.masterViewController).inSplitViewControllerIfSupported(for: $0) } | |
} |
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
class AbsoluteFrameAnimator: NSObject { | |
private var absoluteFrame: CGRect = CGRect.zero | |
init(duration: CGFloat) { | |
self.duration = duration | |
} | |
private let duration: 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
protocol CollectionReusable {} | |
/// Disclaimer: From Apple UI engineer - its allow to force cast the cell in this method, if it fails its mostly another issue in the implementation. | |
/// MARK:- UITableView | |
extension CollectionReusable where Self: UITableViewCell { |
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 | |
// Helpers | |
// takes a list and checks if a given predicate is true for every element O(n) | |
func all<T>(_ xs: [T], predicate: (T) -> Bool) -> Bool { | |
for x in xs { | |
if !predicate(x) { | |
return 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
func convert(_ textValue: String) -> Int{ | |
var total = 0 | |
var valueMap = [ | |
"1" as Character: 1, | |
"2": 2, | |
"3": 3, | |
"4": 4, | |
"5": 5, | |
"6": 6, |
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 fadeHorizontalEdges(in collectionView: UICollectionView, modifier: CGFloat) { | |
let visibleCells = collectionView.visibleCells | |
guard !visibleCells.isEmpty else { return } | |
let firstCell = visibleCells.first! | |
let lastCell = visibleCells.last! | |
visibleCells.forEach { $0.alpha = 1 } | |
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
extension Optional { | |
var isNil: Bool { | |
return self == nil | |
} | |
var isNotNil: Bool { | |
return self != nil | |
} |
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
extension VNFaceObservation { | |
static func overAllBoundingBoxFrom(boundingBoxes: [CGRect], tolerance: CGFloat) -> CGRect { | |
/// Sort Max X coordinates | |
let originXCoordinates = boundingBoxes.map { $0.minX } | |
/// Sort Max Y coordinates | |
let originYCoordinates = boundingBoxes.map { $0.minY } | |
/// Find overall minX |
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
extension UICollectionView { | |
func dynamicGrid(numbersOfSquares :Float) -> (rows: Float, columns: Float, cellSize: CGSize) { | |
let ratio: Float = Float(self.frame.size.width / self.frame.size.height) | |
let numberOfColumns = sqrt(numbersOfSquares * ratio) | |
let numberOfRows = numbersOfSquares / numberOfColumns; | |
// Find best option filling the whole height |