Skip to content

Instantly share code, notes, and snippets.

@kean
Created November 20, 2019 12:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kean/f1418ecc6cecced364e1c4c8c10bed25 to your computer and use it in GitHub Desktop.
Save kean/f1418ecc6cecced364e1c4c8c10bed25 to your computer and use it in GitHub Desktop.
FutureCompatible.swift
// The MIT License (MIT)
//
// Copyright (c) 2016-2019 Alexander Grebenyuk (github.com/kean).
import Foundation
/// Future extenions.
public struct FutureExtension<Base> {
/// Base object to extend.
public let base: Base
/// Creates extensions with base object.
public init(_ base: Base) {
self.base = base
}
}
/// A type that has future extensions.
///
/// - note: In order to add `fx` to a protocol implement `fx` property manually.
public protocol FutureCompatible {
associatedtype CompatibleType
static var fx: FutureExtension<CompatibleType>.Type { get set }
var fx: FutureExtension<CompatibleType> { get set }
}
extension FutureCompatible {
/// Future extensions.
public static var fx: FutureExtension<Self>.Type {
get { return FutureExtension<Self>.self }
set { /* Enabled mutation */ }
}
/// Future extensions.
public var fx: FutureExtension<Self> {
get { return FutureExtension(self) }
set { /* Enabled mutation */ }
}
}
import class Foundation.NSObject
/// Extend NSObject with `fx` proxy.
extension NSObject: FutureCompatible { }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment