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
| // In UserProfileViewController (the master) we need: | |
| // 1 | |
| protocol UserProfileFeedSelectionDelegate: AnyObject { | |
| func postSelectedAt(_ indexPath: IndexPath) | |
| } | |
| // 2 | |
| weak var delegate: UserProfileFeedSelectionDelegate? | |
| // 3 | |
| lazy private var contentDetailViewController: ContentDetailViewcontroller = { |
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
| /// 1 convenience init. | |
| convenience init(viewControllers: [UIViewController]) { | |
| self.init() | |
| /// 2 set master and detail, it takes an array of view controllers. | |
| self.viewControllers = viewControllers | |
| /// 3 preferredDisplayMode, it defines the display mode of the split view controller, | |
| /// .allVisible will display both master and detail. | |
| preferredDisplayMode = .allVisible | |
| /// set the delegate to self to allow the `SplitViewController` handle the UISplitViewControllerDelegate methods. | |
| super.delegate = self |
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
| 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 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
| class AbsoluteFrameAnimator: NSObject { | |
| private var absoluteFrame: CGRect = CGRect.zero | |
| init(duration: CGFloat) { | |
| self.duration = duration | |
| } | |
| private let duration: CGFloat |
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
| 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 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 | |
| // 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 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
| 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 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
| 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 } | |