lundi 22 juin 2015

Final self class for generics, in method signature, in Swift

I have a BaseObject model that defines common behaviour I want to share across all my data entities. It has a method like this:

class BaseObject {
    static func fetch(block: ((Results<BaseObject>) -> Void)) {
        // networking code here
    }
}

Naturally, I need the signature of this method be dynamic enough so that a model of class Products

class Products: BaseObject { //...

yields a Results<Products> list instead of Results<BaseObject>. I don't want to re-implement the fetch method in every subclass, because, save for the exact final subclass name used in the body and in the signature, it would be identical.

I cannot use Self:

Xcode error

Do I have any options at all?





Aucun commentaire:

Enregistrer un commentaire