Skip to content

Instantly share code, notes, and snippets.

View yucelokan's full-sized avatar

Okan Yücel yucelokan

  • Turkcell
  • Kocaeli
View GitHub Profile
import Foundation
public extension DispatchQueue {
/**
- parameters:
- target: Object used as the sentinel for de-duplication.
- delay: The time window for de-duplication to occur
- work: The work item to be invoked on the queue.
Performs work only once for the given target, given the time window. The last added work closure
is the work that will finally execute.
@yucelokan
yucelokan / LottieFinder.swift
Last active October 19, 2022 13:21
A general hack to prevent Lottie animations from stopping playing after pushing/popping/presenting/dismissing.
// A general hack to prevent Lottie animations from stopping playing after pushing/popping/presenting/dismissing.
// Usage: LottieFinder.setupLottieFinder()
import UIKit
import Lottie
class LottieFinder {
static private var operationQueue = OperationQueue()
static private var operations: [Operation] = []
static func setupLottieFinder() {
@yucelokan
yucelokan / UIFont+Manipulation.swift
Created October 19, 2022 13:12
A hack that modifies the values for UIFont read-only properties ascender and descender.
// A hack that modifies the values for UIFont read-only properties ascender and descender.
// Usage: UIFont.manipulateFont()
extension UIFont {
static func manipulateFont() {
swizzleFont()
}
static func swizzleFont() {
@yucelokan
yucelokan / UIView+Animation.swift
Created September 29, 2022 07:52
Animation extension for UIView.
public extension UIView {
func fader(
duration: CGFloat,
delay: CGFloat = 0,
fromValue: CGFloat = 0,
toValue: CGFloat = 1,
curve: UIView.AnimationCurve = .easeOut,
completion: (() -> Void)? = nil
) {
alpha = fromValue
@yucelokan
yucelokan / ReusableViews+Extension.swift
Last active September 29, 2022 07:56
To register and dequeue cells.
public extension UIView {
class var identifier: String {
String(describing: self)
}
}
public extension UITableView {
func registerNib(_ type: UITableViewCell.Type, bundle: Bundle) {
register(
UINib(nibName: type.identifier, bundle: bundle),
@yucelokan
yucelokan / UIApplication+UIViewController.swift
Created September 29, 2022 07:46
An extension to create an instance for UIViewController in the Storyboard.
// usage -> let viewController: ACustomViewController = UIApplication.getViewController()
public extension UIApplication {
class func getViewController<T: UIViewController>(
inScene named: String? = nil,
rootViewController: Bool = true
) -> T {
let controllerName = String(describing: T.self)
let storyboardName = named ?? substringStoryboardName(withViewControllerName: controllerName)
if rootViewController,
let viewController = UIStoryboard(
@yucelokan
yucelokan / Collection+Safe.swift
Last active October 19, 2022 13:22
An extension to access safely to items in an array.
// An extension to access safely to items in an array.
// usage:
// let anArray: [Item] = [......]
// let item = anArray[safe: 5]
public extension Collection {
subscript(safe index: Index) -> Element? {
indices.contains(index) ? self[index] : nil
}
}
@yucelokan
yucelokan / UIView+Initialize.swift
Created September 29, 2022 07:40
An extension to initialize custom view.
// please don't forget to add the custom class for your UIView on the interface builder.
public extension UIView {
static func initFromNib() -> Self {
guard let view = UINib(nibName: String(describing: self), bundle: nil)
.instantiate(withOwner: nil, options: nil).first as? Self else {
fatalError("Could not init view")
}
return view
}
}
@yucelokan
yucelokan / YOOrderedDictionary.swift
Created September 29, 2022 07:20
Ordered Dictionary
//
// YOOrderedDictionary.swift
//
//
// Created by okan.yucel on 12.04.2022.
//
import Foundation
class YOOrderedDictionary<Key: Hashable, Value> {