Skip to content

Instantly share code, notes, and snippets.

View shaps80's full-sized avatar
🔥
Work with me!

Shaps shaps80

🔥
Work with me!
View GitHub Profile
final class Example {
func emptyTask() {
TODO
}
func slowTask() {
FIXME
print("This still executes")
}
@shaps80
shaps80 / NibLoadable.swift
Created May 9, 2017 21:14
Provides an opt-in approach to loading views and viewControllers from UINib's and UIStoryboard's.
//
// NibLoadable.swift
// KoreanAir
//
// Created by Shahpour Benkau on 27/04/2017.
// Copyright © 2017 Korean Air. All rights reserved.
//
import UIKit
//
// IndexPathSelection.swift
// Credit: https://www.raizlabs.com/dev/2016/05/smarter-animated-row-deselection-ios/
//
// This version by Shahpour Benkau on 21/05/2017 – based on the version from raizlabs.com
//
import UIKit
// Represents a view that provides indexPath selection (e.g. UITableView, UICollectionView)
@shaps80
shaps80 / CGRect+Reversible.swift
Last active June 21, 2017 09:01
Returns a reversible rect, great for producing marquee selection rectangles.
extension CGRect {
public static func reversible(from: CGPoint, to: CGPoint) -> CGRect {
let size = CGSize(width: to.x - from.x, height: to.y - from.y)
return CGRect(origin: from, size: size).standardized
}
}
@shaps80
shaps80 / ExampleUsage.swift
Created June 23, 2017 13:59
Demonstrates weak-ifying a closure/owner pair to ensure retain cycles are not introduced.
weakify(observer, updates)(self)
@shaps80
shaps80 / InfiniteIterator.swift
Created October 20, 2017 12:08
An iterator that automatically wraps back to the `firstIndex` after the `endIndex` is reached.
import Foundation
public struct InfiniteIterator<Base: Collection>: IteratorProtocol {
private let collection: Base
private var index: Base.Index
public init(collection: Base) {
self.collection = collection
self.index = collection.startIndex
@shaps80
shaps80 / AVPlayer+Scrubbing.swift
Last active November 4, 2025 14:39
Enables smooth frame-by-frame scrubbing (in both directions) – similar to Apple's applications.
public enum Direction {
case forward
case backward
}
internal var player: AVPlayer?
private var isSeekInProgress = false
private var chaseTime = kCMTimeZero
private var preferredFrameRate: Float = 23.98
@shaps80
shaps80 / Scheduling-AppDelegate.swift
Last active February 16, 2022 03:14
NSNotification Scheduling Service in Swift. (the only required file is `SchedulingService.swift`)
//
// AppDelegate.swift
// Scheduling
//
// Created by Shaps Benkau on 19/02/2018.
// Copyright © 2018 152percent Ltd. All rights reserved.
//
import UIKit
@shaps80
shaps80 / Constraints.swift
Last active March 29, 2018 14:13
Swift Constraints Micro DSL
#if os(iOS)
import UIKit
#else
import Cocoa
public typealias UIView = NSView
public typealias UILayoutPriority = NSLayoutConstraint.Priority
#endif
public typealias Constraint = (_ view: UIView, _ otherView: UIView?) -> NSLayoutConstraint
@shaps80
shaps80 / Collection+NilEmpty.swift
Last active May 4, 2018 09:26
Adds `isNilOrEmpty` to any `Collection` – Swift 4
public extension Optional where Wrapped: Collection {
/// Equivalent to `if let value = value, !value.isEmpty`
///
/// Useful when you need to know whether or not an underlying value exists at all.
///
/// string.isNilOrEmpty
///
/// Returns true if `string` is nil or empty. False otherwise
var isNilOrEmpty: Bool {