Skip to content

Instantly share code, notes, and snippets.

@rickytan
Created December 8, 2023 16:00
Show Gist options
  • Save rickytan/d65f3456f7895a6290f892c39f07dada to your computer and use it in GitHub Desktop.
Save rickytan/d65f3456f7895a6290f892c39f07dada to your computer and use it in GitHub Desktop.
Swift Namewrapper
public struct NameWrapper<Base> {
public let base: Base
public init(_ base: Base) {
self.base = base
}
}
public protocol NameWrapperCompatiable {
associatedtype Base
static var <#namespace#>: NameWrapper<Base>.Type { get set }
var <#namespace#>: NameWrapper<Base> { get set }
}
public extension NameWrapperCompatiable {
var <#namespace#>: NameWrapper<Self> {
get { return NameWrapper(self) }
// swiftlint:disable:next unused_setter_value
set { }
}
static var <#namespace#>: NameWrapper<Self>.Type {
get { return NameWrapper<Self>.self }
// swiftlint:disable:next unused_setter_value
set { }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment