[swift-evolution] [Pitch] Adding a Self type name shortcut for static member access
Timothy Wood
tjw at me.com
Tue Apr 5 15:06:44 CDT 2016
> On Apr 5, 2016, at 11:41 AM, Russ Bishop <xenadu at gmail.com> wrote:
>
> But if you don’t want subclasses to override it then why are you making it internal/public in the first place?
I'm wan’t talking about overriding it… In my earlier posts I was talking about subclasses being able to call a utility function on their superclass and have a generic be expanded to the subclass type (whatever it is) by using `#Self`.
So, if the superclass `PropertyOwner ` has something like this (excusing typos since this code can’t be compiled right now, obviously =) ...
static func property<Owner: PropertyOwner, ValueType>(ownerType: Owner.Type = #Self.self, name: String, value: ValueType)
then a subclass `Sub` could do:
static let foozle = property(name: “foozle”, value: Int(3))
and end up with `foozle` being configured with ownerType = Sub.self. If later this property is moved to a different class, its ownerType would automatically change based on its new scope.
-tim
More information about the swift-evolution
mailing list