mercredi 2 décembre 2015

Definite class name in a singleton method

Here is a sample code of a singleton method:

+ (id)sharedManager {
    static MyManager *sharedMyManager = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        sharedMyManager = [[self alloc] init];
    });
    return sharedMyManager;
}

Is there a way to get rid of the certain class name declaration MyManager * and replace it with some abstract type like self * or instancetype?

Aucun commentaire:

Enregistrer un commentaire