dimanche 28 juin 2015

Can this dispatch_once singleton ever return nil?

Trying to find an issue we are experiencing intermittently, that seems to be occurring on devices with low memory conditions. The suspected cause is the NSDateFormatter singleton being nil.

Is there any possible situation where the singleton pattern below could return nil?

+ (NSDateFormatter *)dateFormatterUTC {

    static NSDateFormatter *formatter;
    static dispatch_once_t onceToken;

    dispatch_once(&onceToken, ^{
        formatter = [[NSDateFormatter alloc] init];
        formatter.dateFormat=@"yyyy-MM-dd HH:mm:ss ZZZ";
    });

    return formatter;
}

Aucun commentaire:

Enregistrer un commentaire