The first one has this at the start:
static NSDateFormatter *dateFormatter = nil;
if (dateFormatter == nil) {
dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"dd.MM.yyyy"];
}
... so it does that.
The second one has this:
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"dd.MM.yyyy"];
... so it does that instead.
I'm here all week.
Let's look at what the second one is doing first. It's creating a date formatter, and telling it what format dates it wants. It then gets that date formatter to format the current date. It does all those steps every time.
The second one creates a date formatter, but only if it hasn't already done so. It hangs onto the date formatter by putting it in a static variable. It then gets the formatter to format the current date
If they only run once, they're pretty much the same; the first will be infinitesimally slower because it has to do the check. The difference comes if they run lots of times. The first one runs like this:
Create a date formatter
Format the date
Create a date formatter
Format the date
Create a date formatter
Format the date
...
The second one runs like this:
Check for a date formatter
Create a date formatter
Format the date
Check for a date formatter
Format the date
Check for a date formatter
Format the date
...
Creating a date formatter is a very expensive operation, but checking for one isn't, so if the function is called lots of times, the second version is much faster.