Last active
September 1, 2018 04:29
-
-
Save sugarmo/97f6eddd112ae9eea9ef7f43ca228ab9 to your computer and use it in GitHub Desktop.
Swift Extension with Namespace
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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