Skip to content
master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 

HCDates

HCDates makes dealing with fixed NSDateFormatters easier and more efficient.

Rather than setting up a new date formatter every time you can just call +[NSDateFormatter dateFormatterWithFormat:]. This will return a cached NSDateFormatter using the en_US_POSIX locale.

As long as the cache hasn't been cleared the call will return the same formatter every time:

NSString *format = @"#DATE_FORMAT#";

NSDateFormatter *dateFormatter1 = [NSDateFormatter dateFormatterWithFormat:format];
NSDateFormatter *dateFormatter2 = [NSDateFormatter dateFormatterWithFormat:format];

if (dateFormatter1 == dateFormatter2)
{
    NSLog(@"The NSCache has *not* been purged");
}
else
{
    NSLog(@"The NSCache has been purged, this can happen can if memory is tight");
}

[NSDateFormatter purgeDateFormatterCache];

NSDateFormatter *dateFormatter3 = [NSDateFormatter dateFormatterWithFormat:format];

NSAssert(dateFormatter1 != dateFormatter3, @"As the cache has been purged a new date formatter has been created");

Adds enUSPOSIXLocale to NSLocale

This is just a convenience method to reuse en_US_POSIX.

About

HCDates makes dealing with fixed NSDateFormatters easier and more efficient.

Resources

License

Packages

No packages published