Skip to content

Instantly share code, notes, and snippets.

View hitendradeveloper's full-sized avatar
PRO

Hitendra developer hitendradeveloper

PRO
View GitHub Profile
@IanKeen
IanKeen / UIControl.swift
Created April 3, 2016 21:04
UIControl.swift - Adds a closure based target/action support to all UIControl based components, including basic lifecycle handling
public protocol ClosureActionable: class {
func addTarget(target: AnyObject, forControlEvents controlEvents: UIControlEvents, closure: (Self) -> Void) -> AnyObject
func removeTarget(pointer: AnyObject)
}
extension UIControl: ClosureActionable { }
public extension ClosureActionable where Self: UIControl {
private var pointers: [TargetPointer] {
get {
if let existing = objc_getAssociatedObject(self, ClosureAssociatedKeys.Pointers) as? [TargetPointer] { return existing }
@IanKeen
IanKeen / NSTimeInterval+Extension.swift
Last active October 16, 2019 04:32
Working Swiftly with NSTimeInterval
enum TimePeriod {
case Seconds(Int)
case Minutes(Int)
case Hours(Int)
var timeInterval: NSTimeInterval {
switch self {
case .Seconds(let value): return NSTimeInterval(value)
case .Minutes(let value): return NSTimeInterval(value * 60)
case .Hours(let value): return NSTimeInterval(value * 60 * 60)
@IanKeen
IanKeen / NibLoadableView.swift
Last active May 9, 2018 17:30
Class to allow you to use NIB BASED custom UIView in interface builder
import UIKit
open class NibLoadableView: UIView {
//MARK: - Public Properties
private(set) var customView: UIView!
//MARK: - Lifecycle
public required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
self.nibSetup()
@IanKeen
IanKeen / IKScrollView.swift
Last active November 18, 2021 16:34
A UIScrollView subclass that allows you to use scrollviews and autolayout without the drama...
enum SizeMatching {
case Width, Height, Both, None
}
class IKScrollView: UIScrollView {
//MARK: - Outlets
@IBOutlet private var contentView: UIView?
//MARK: - Properties
@IBInspectable var sizeMatching = SizeMatching.Width