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 String { | |
subscript(_ i: Int) -> Character { | |
self[index(startIndex, offsetBy: i)] | |
} | |
} |
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
fileprivate extension Result { | |
func get() throws -> Success { | |
switch self { | |
case .success(let value): return value | |
case .failure(let error): throw error | |
} | |
} | |
var data: Success? { | |
return switch self { |
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
// | |
// DispatchQueue+Debounce.swift | |
// | |
// Created by Abhishek Maurya on 22/05/24. | |
// | |
import Foundation | |
public extension DispatchQueue { | |
func debounce(after interval: Int, action: @escaping (Any?) -> Void) -> (Any?) -> Void { |
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
// | |
// UIView+AddSubview+Constraints.swift | |
// | |
// Created by Abhishek Maurya on 22/04/23. | |
// | |
extension UIView { | |
func addSubview(_ subView: UIView, considerSafeArea: Bool = false, with constraints: Array<Constraints>) -> [NSLayoutConstraint] { | |
addSubview(subView) | |
return subView.addConstraints(in: self, considerSafeArea: considerSafeArea, with: constraints) |
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
// | |
// UIAnimatableLabel.swift | |
// | |
// Created by Abhishek Maurya on 04/04/23. | |
// | |
import UIKit | |
// MARK: - UIAnimatableLabel | |
final class UIAnimatableLabel: UILabel { |
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 CollectionSnapFlowLayout: UICollectionViewFlowLayout { | |
var onlyScrollToNext: Bool = true | |
override func targetContentOffset(forProposedContentOffset proposedContentOffset: CGPoint, withScrollingVelocity velocity: CGPoint) -> CGPoint { | |
guard let collectionView = self.collectionView else { | |
let latestOffset = super.targetContentOffset(forProposedContentOffset: proposedContentOffset, withScrollingVelocity: velocity) | |
return latestOffset | |
} /// Add some snapping behaviour so that the cell is always centered | |
var proposedX: CGFloat = proposedContentOffset.x |
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 GradientTextLabel: UILabel { | |
var gradientColors: [CGColor] = [UIColor.orangeRed.cgColor, UIColor.brightRed.cgColor, UIColor.warmPurple.cgColor, UIColor.darkishBlue.cgColor] | |
var locations: [CGFloat]? = [0.0, 0.25, 0.5, 0.75] | |
override func drawText(in rect: CGRect) { | |
if let gradientColor = drawGradientColor(in: rect, colors: gradientColors) { | |
self.textColor = gradientColor | |
} | |
super.drawText(in: rect) | |
} |
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 GradientView: UIImageView { | |
var gradientColors: [CGColor] = [UIColor.greyishBrown.withAlphaComponent(0.2).cgColor, UIColor.greyishBrown.cgColor] | |
var locations: [CGFloat]? = [0.0, 1.0] | |
override func layoutSubviews() { | |
self.contentMode = .scaleToFill | |
self.backgroundColor = .hotPink | |
self.image = drawGradientColor(in: self.bounds, colors: gradientColors) | |
} |
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 collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { | |
let totalAvailableWidth = collectionView.bounds.width | |
let padding: CGFloat = 25 | |
let interSpace: CGFloat = 15 | |
let numOfCellInaRow: CGFloat = 3 | |
let cellWidth: CGFloat = (totalAvailableWidth - (padding * 2) - (interSpace * (numOfCellInaRow - 1))) / numOfCellInaRow | |
/// padding * 2 = leading + trailing space, (interSpace * (numOfCellInaRow - 1)) = totalInterspacing as 3 cells will have 2 interspace | |
let cellSize = CGSize(width: cellWidth, height: cellWidth) | |
return cellSize | |
} |
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 | |
// Confirm this to your cell/header if using Prototype cell | |
public protocol ReusableView: AnyObject { | |
static var defaultReuseIdentifier: String { get } | |
} | |
extension ReusableView where Self: UIView { | |
public static var defaultReuseIdentifier: String { | |
return String(describing: self) |
NewerOlder