Casper522
Casper522

Reputation: 95

dateFromString prints out "(null)"

I know that there are lots of questions about this, but none of the answers seem to be working for me. Here's my code (iOS SDK 6.0)

NSDateFormatter *df = [NSDateFormatter alloc];
[df setDateFormat:@"yyyy-MM-dd"];
[df setFormatterBehavior:NSDateFormatterBehavior10_4];
[df setTimeZone:[NSTimeZone defaultTimeZone]];
[df setLocale:[NSLocale currentLocale];
NSDate *TERMIN = [NSDate alloc];
TERMIN = [df dateFromString:T]; //'T' is date in string NSLog(...,T) is 2002-05-05

When I output TERMIN through NSLog the output is (null)

Upvotes: 0

Views: 116

Answers (2)

Casper522
Casper522

Reputation: 95

OK this is kinda akward, i was NSLoging like object.variable instead of [object getVariable] from outside...that was the whole problem. Sorry to bother you guys, im such a dumb*ss :D

Another problem showed up that the code above turns 2002-05-05 into 2002-05-04. But that is for another story i guess...

Upvotes: 0

iRaivis
iRaivis

Reputation: 169

You forgot to initialize the NSDateFormatter object

NSDateFormatter *df = [[NSDateFormatter alloc] init];

Upvotes: 1

Related Questions