Can you let me know if this is currently being worked on? I can't upgrade my existing Swift 1.x code-base as a result which has been written to rely on this - a hard fought working approach since the broken reflection support in Swift 1.x forced.
This is a subset of what I'm trying to achieve, it fails with "Type may not reference itself as a requirement" in Swift 2.0 and I'm not able to use the second protocol hack described above to resolve it:
public protocol HasMetadata {
typealias T : HasMetadata //fails with: Type may not reference itself as a requirement
static func metadata() -> Metadata<T>
}
public class Metadata<T : HasMetadata> {
public var properties:[String:(T) -> Int]
init(properties:[String:(T) -> Int]){
self.properties = properties
}
}
public class Test
{
required public init(id:Int) {
self.id = id
}
public var id:Int = 0
}
extension Test : HasMetadata {
public static func metadata() -> Metadata<Test> {
return Metadata<Test>(properties: ["id": { $0.id }])
}
}
So it can be used like:
print(Test.metadata().properties["id"](Test(1)))
Does anyone know how this can be rewritten in Swift 2.0?