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 var StringIdentifierHandle: UInt8 = 2 | |
extension UIView { | |
var stringIdentifier: String? { | |
get { | |
return objc_getAssociatedObject(self, &StringIdentifierHandle) as? String | |
} | |
set { | |
objc_setAssociatedObject(self, &StringIdentifierHandle, newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC) |
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
// Thanks to following StackOverflow answer: | |
// https://stackoverflow.com/questions/47597489/compare-swift-enum-types-ignoring-associated-values-generic-implementation | |
protocol ComparableCaseEnum { | |
func isSameCase(as other: Self) -> Bool | |
} | |
extension ComparableCaseEnum { | |
func isSameCase(as other: Self) -> Bool { | |
let mirrorSelf = Mirror(reflecting: 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
extension Collection { | |
/// Returns the element at the specified index if it is within bounds, otherwise nil. | |
subscript (safe index: Index) -> Element? { | |
return indices.contains(index) ? self[index] : 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
enum PersonInfo { | |
// CustomDebugStringConvertible is here for easier printing to console. | |
// Feel free to remove it if you don't need it. | |
class EnumValue<T>: CustomDebugStringConvertible { | |
var value: T | |
init(_ value: T) { | |
self.value = value | |
} |
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 UIView { | |
//MARK: - XIBs | |
// https://stackoverflow.com/questions/24857986/load-a-uiview-from-nib-in-swift | |
public class var nibName: String { | |
let name = "\(self)".components(separatedBy: ".").first ?? "" | |
return name | |
} | |
public class var nib: UINib { |
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 UIStoryboard { | |
func instantiateViewController<T: UIViewController>() -> T { | |
let viewController = self.instantiateViewController(withIdentifier: T.className) | |
guard let typedViewController = viewController as? T else { | |
fatalError("Unable to cast view controller of type (\(type(of: viewController))) to (\(T.className))") | |
} | |
return typedViewController | |
} |
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
// | |
// FadeOperation.swift | |
// SomeProject | |
// | |
// Created by Josip Bernat on 03/11/2017. | |
// Copyright © 2017 Josip's Home. All rights reserved. | |
// | |
import Foundation | |
import AVFoundation |