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 |
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 PHAsset { | |
// MARK: This returns an array of alternate assets from a PHAsset | |
func getAlternatePhotos() -> [PHAsset] { | |
/// get the collection of the asset to avoid fetching all photos in the library | |
let collectionFetchResult = PHAssetCollection.fetchAssetCollectionsContaining(self, with: .moment, options: nil) | |
let options = PHFetchOptions() | |
options.sortDescriptors = [NSSortDescriptor.init(key: "creationDate", ascending: true)] |