Skip to content

Instantly share code, notes, and snippets.

View DevAndArtist's full-sized avatar
🦅
Hacking in Swift

Adrian M. DevAndArtist

🦅
Hacking in Swift
View GitHub Profile
func ?? <T>(_ optional: T?, _ trap: @autoclosure () -> Never) -> T {
	switch optional {
	case .some(let value):
		return value
	case .none:
		trap()
	}
}
@DevAndArtist
DevAndArtist / Logger.swift
Last active December 8, 2017 15:11
Logger (WIP)
import Darwin
import UIKit
protocol _LoggerDelegate : AnyObject {
///
func logger(_ logger: Logger, received newString: String)
}
final class Logger {
///
import UIKit

protocol ViewComponent : AnyObject {
  ///
  func isAncestor(of descendant: Self) -> Bool

  ///
  func isDescendant(of ancestor: Self) -> Bool
import RxSwift
public final class DisposeCache<Key>
: ExpressibleByDictionaryLiteral where Key : Hashable {
///
private var lock = NSRecursiveLock()
///
private var storage: [Key: Disposable]
protocol ValueContainer {
associatedtype Value
var value: Value { get }
init(_ value: Value)
}
extension ValueContainer where Self : Equatable, Value : Equatable {
static func == (lhs: Self, rhs: Self) -> Bool {
return lhs.value == rhs.value
}
@DevAndArtist
DevAndArtist / deinit-experiment.swift
Created September 13, 2018 14:25
Deinit experiement
class Ref {
weak var obj: Obj? {
didSet { print("didSet", obj as Any) }
}
}
class Obj {
weak var ref: Ref?
func unlink(from ref: Ref) {
public struct Unique<Key, Value>: Hashable where Key: Hashable {
public enum KeyVariant {
case key(Key)
case keyPath(KeyPath<Value, Key>)
case closure((Value) -> Key)
internal func _key(for value: Value) -> Key {
switch self {
case .key(let key):

Application Development Techniques

Drivable UI

@dynamicMemberLookup
struct DriverFor<Base> {
 var base: Base
@DevAndArtist
DevAndArtist / Property Delegates.md
Last active March 24, 2019 10:38
Property Delegates

WWDC 2019 Labs Questions

Size changes propagation to child view controller

In A Look Inside Presentation Controllers - WWDC 2014 session the following pattern was introduced.

  • A child view controller or a presented view controller can issue a request for size update by setting its preferredContentSize property.
  • A parent view controller or a presentation controller will receive a callback on preferredContentSizeDidChangeForChildContentContainer method.
  • At this point the receiver can decide if can allow the size request and layout the child view controller or the presented view controller.