Skip to content

Instantly share code, notes, and snippets.

View 0xLeif's full-sized avatar
🇺🇦

Zach 0xLeif

🇺🇦
View GitHub Profile
@0xLeif
0xLeif / TFObservable.swift
Last active March 16, 2019 02:46
RxSwift SubscribeIf
import UIKit
import RxSwift
class TFObservable<E> {
var disposable: Disposable
private var trueBlock: ((E) -> Void)?
private var falseBlock: ((E) -> Void)?
init() {
@0xLeif
0xLeif / Builder.swift
Created March 16, 2019 02:44
Swift Builder
import Foundation
protocol Buildable {
init()
init(_ build: (inout Self) -> Self)
}
extension Buildable {
init(_ build: (inout Self) -> Self) {
var s = Self()
@0xLeif
0xLeif / bool.swift
Created March 16, 2019 02:45
Conditional
extension Bool {
func `if`(_ block: () -> Bool) -> Bool {
return self ? block() : self
}
func `true`(_ block: () -> Void) -> Bool {
if self {
block()
}
@0xLeif
0xLeif / KP.swift
Last active August 21, 2020 22:21
KeyPath
import UIKit
precedencegroup KeyPathPrecedence {
associativity: right
higherThan: MultiplicationPrecedence
}
infix operator ...: KeyPathPrecedence
@0xLeif
0xLeif / UI.swift
Created October 28, 2019 16:34
UIBuildable
import UIKit
postfix operator ...
protocol UIConfigurable {
func configure<T>(_ configure: (inout T) -> Void) -> T
static func ...<T>(_ lhs: Self, _ block: (inout T) -> Void) -> T
}
extension UIView: UIConfigurable {
@0xLeif
0xLeif / keybase.md
Last active February 19, 2020 17:16
keybase

Keybase proof

I hereby claim:

  • I am 0xLeif on github.
  • I am l_eif (https://keybase.io/l_eif) on keybase.
  • I have a public key ASDxGDsRglqF5yBeAx4l6hLrEzjDrk6kVIz4S44CQ_GU4wo

To claim this, I am signing this object:

@0xLeif
0xLeif / use.swift
Created November 29, 2019 18:08
Optional Use
import Foundation
public extension Optional {
func use(_ closure: (Wrapped) -> Void) {
guard let unwrappedSelf = self else {
return
}
closure(unwrappedSelf)
}
}
//
// NSObjectProtocol+Swift.swift
//
//
// Created by Zach Eriksen on 10/30/19.
//
import Foundation
public extension NSObjectProtocol {
@discardableResult
//
// NSMutableAttributedString+Swift.swift
//
//
// Created by Zach Eriksen on 12/11/19.
//
import Foundation
public typealias AttributedString = NSMutableAttributedString
public typealias AttributedStringKey = NSAttributedString.Key
@0xLeif
0xLeif / LazyTable.swift
Created January 17, 2020 23:20
LazyTable
class LazyTable: UITableView {
fileprivate var loadThreshold: CGFloat = 0.75 // 75%
fileprivate var loadAmount: Int = 25
fileprivate var loadCount: Int = 1
fileprivate var batchCount: Int {
return loadAmount * loadCount
}
fileprivate var elements: [UIView] = [] {
didSet {