SimplyKiwi
SimplyKiwi

Reputation: 12442

Make this code more efficient?

I have the below code, and I would like to make it more efficient. Currently it is a tad slow and I want to make it faster. I know there is something I can do here but not sure what to do to make it more efficient. Here is the code:

NSDate *now = [NSDate date];
NSDateFormatter* formatter = [[[NSDateFormatter alloc] init] autorelease];
[formatter setDateFormat:@"MM-dd-yyyy"];
NSString *dateString = [formatter stringFromDate:now];
NSDate *enddate = [formatter dateFromString:dateString];
[[NSUserDefaults standardUserDefaults] setObject:enddate forKey:@"theDate"];

Thanks!

Upvotes: 0

Views: 80

Answers (1)

smitec
smitec

Reputation: 3049

So to me it looks like you want to store a formatted version of the current date in the UserDefaults file under the key "theDate" (correct me if I'm wrong).

could you not just use the line: [[NSUserDefaults standardUserDefaults] setObject:[NSDate date] forKey:@"theDate"];

and then deal with the formatting when (or if) it is actually displayed.

Upvotes: 3

Related Questions