MFDateFormatterPool is a Cache Pool for NSDateFormatter instances.
Creating the NSDateFormatter or changing the date style or time style is very expensive, as the experiments done by someone . It takes long time to initialize the instance. What we should do is creating each style of date formatter once and use it the whole project.
MFDateFormatterPool created the cache by NSCache. The first time you created the NSDateFormatter
, it will cache the instance for you. If you need to use the same date formatter style, it will return the old one for you instead of creating a new one, which is too expensive.
Using the MFDateFormatterPool is very easy:
MFDateFormatterPool *myDateFormatterPool = [MFDateFormatterPool sharedInstance];
NSString *myFormat = @"yyyy:MM:dd HH:mm:ss";
NSDateFormatter *myFirstFormatter = [myDateFormatterPool dateFormatterWithFormat:myFormat];
NSDateFormatter *mySecondFormatter = [myDateFormatterPool dateFormatterWithFormat:myFormat];
If you are using swift:
let myDateFormatter0 = DateFormatterPool.shared.dateFormatter(dateStyle: .full, timeStyle: .full)
let myDateFormatter1 = DateFormatterPool.shared.dateFormatter(formatter: "yyyy:MM:dd HH:mm:ss")
Please issue me, send emails(wallaceicdi@gmail.com) or twitter me(https://twitter.com/MikeFighting), if you have any problems using this tool.