Skip to content

Instantly share code, notes, and snippets.

View amfathi's full-sized avatar
🎧

Ahmed Fathi amfathi

🎧
View GitHub Profile
@amfathi
amfathi / LocalAuth.Swift
Last active April 26, 2019 21:21
Helper class for LocalAuthentication.
import Foundation
import LocalAuthentication
/// `AuthenticationFallbackType` is the backup authentication method if `touchID` user used was invalid.
///
/// Don't Forget to add `LocalAuthentication.framework` into your `Linked Frameworks and Librarys`.
enum AuthenticationFallbackType {
/// Keep trying with `touchID` only. No other methods to authenticate the user.
case none
@amfathi
amfathi / Dictionary+jsonView.swift
Last active May 1, 2020 20:56
Convert swift dictionary to JSON view. Helpful for copy-paste data from console to postman.
extension Dictionary {
func jsonView() -> String {
guard let data = try? JSONSerialization.data(withJSONObject: self, options: .prettyPrinted) else { return "" }
return String(data: data, encoding: .utf8) ?? ""
}
}
@amfathi
amfathi / AlertBuilder.swift
Last active February 28, 2020 09:51
Ease how to use your UIAlertController.
import UIKit
extension UIAlertController {
// MARK: - Alert Types
static func alert(title: String = "", message: String = "") -> UIAlertController {
return UIAlertController(title: title, message: message, preferredStyle: .alert)
}
static func sheet(title: String = "", message: String = "") -> UIAlertController {
@amfathi
amfathi / GradientView.swift
Last active April 26, 2019 21:22
GradientView with animate func.
import UIKit
class GradientView: UIView {
private var gradientLayer: CAGradientLayer!
let startColor: UIColor = .blue
let endColor: UIColor = .red
let startPointX: CGFloat = 0
let startPointY: CGFloat = 0.5
@amfathi
amfathi / PopupViewController.swift
Last active February 13, 2021 17:26
Animated fade in/out popup.
import UIKit
class PopupViewController: UIViewController {
var viewToAnimate: UIView?
lazy var transform: CGAffineTransform = {
return CGAffineTransform.identity.scaledBy(x: 0.01, y: 0.01)
}()
override func viewWillAppear(_ animated: Bool) {
extension UIColor {
enum AssetIdentifier: String {
case darkRed
case fadedRed = "customFadedRed"
}
convenience init!(asset: AssetIdentifier) {
self.init(named: asset.rawValue)
}
import UIKit
/// A protocol for easy use of `UIActivityIndicators` (Spinners).
protocol SpinnerCompatible: class {
/// Adds an activity indicator to the the view. Disables the view interaction as long as the spinner is displayed.
/// Call `hideSpinner()` to hide it.
/// - parameter color: color of the spinner. Default value is `gary`.
/// - parameter dims: optional bool to dim the holding view while displaying the spinner. Default value is `false`.
/// - parameter blocks: optional bool to block the holding view while displaying the spinner. Default value is `true`.
@amfathi
amfathi / CoreDataManager.swift
Last active February 28, 2020 09:52
CoreDataSupport (iOS10 and above)
import Foundation
import CoreData
// MARK: - CoreData Protocols
protocol CoreDataRetrivable {
init(managedObject: NSManagedObject)
}
protocol CoreDataStorable {
@discardableResult
@amfathi
amfathi / BaseCollectionViewCell.swift
Last active July 15, 2022 10:35
**Base** Views and Controllers (SnapKit + RxSwift)
import UIKit
class BaseCollectionViewCell: UICollectionViewCell, Identifiable {
override init(frame: CGRect) {
super.init(frame: .zero)
setupViews()
setupConstraints()
}
@amfathi
amfathi / BaseNavigationCoordinator.swift
Last active February 21, 2025 17:06
Coordinator (NavigationCoordinator + TabBarCoordinator)
import UIKit
// MARK: - Base Coordinator
class NavigationCoordinator: NSObject, Coordinator {
weak var parentCoordinator: Coordinator?
var childCoordinators = [Coordinator]()
var navigationController: BaseNavigationController
weak var startViewController: UIViewController?