[swift-evolution] Binding generic types using a metatype parameter

Joanna Carter joanna at carterconsulting.org.uk
Thu Mar 24 08:12:11 CDT 2016


I want to thank you for your "rubber duck" consultancy; I now have a working factory mechanism…

protocol PropertyFactory { }

extension PropertyFactory
{
  static func createProperty() -> PropertyProtocol
  {
    typealias ValueType = Self
    
    return Property<ValueType>()
  }
}

extension Int : PropertyFactory { }

The key was to typealias Self so that it could then be passed as a type parameter to the generic type.

The problem remains that it is still necessary to implement PropertyFactory on each and every type that is likely to be used for a property.

I would therefore ask if anything that would make life simpler in this regard is a worthwhile candidate for inclusion in the future of Swift?

Joanna

--
Joanna Carter
Carter Consulting



More information about the swift-evolution mailing list