Skip to content

Instantly share code, notes, and snippets.

@sugarmo
Last active September 1, 2018 04:29
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 sugarmo/97f6eddd112ae9eea9ef7f43ca228ab9 to your computer and use it in GitHub Desktop.
Save sugarmo/97f6eddd112ae9eea9ef7f43ca228ab9 to your computer and use it in GitHub Desktop.
Swift Extension with Namespace
public protocol NamespaceWrappable {
associatedtype T
var ex: T { get }
static var ex: T.Type { get }
}
extension NamespaceWrappable {
public var ex: TypeWrapper<Self> {
return TypeWrapper(value: self)
}
public static var ex: TypeWrapper<Self>.Type {
return TypeWrapper.self
}
}
public struct TypeWrapper<T> {
var value: T
init(value: T) {
self.value = value
}
}
extension String: NamespaceWrappable {}
public extension TypeWrapper where T == String {
// extension code
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment