Re: Trouble comparing NSCalendarDates
Re: Trouble comparing NSCalendarDates
- Subject: Re: Trouble comparing NSCalendarDates
- From: Tito Ciuro <email@hidden>
- Date: Mon, 15 Nov 2004 10:56:30 +0100
On Nov 15, 2004, at 10:32, j o a r wrote:
On 2004-11-15, at 10.17, Tito Ciuro wrote:
2) Later, when I need to retrieve it from disk, I call returnedValue = [[[NSCalendarDate alloc] dateWithCalendarFormat:dateData] timeZone:nil]autorelease];
No, that's not right - what do you *really* call?
The data is retrieved from a SQLite database and is a 'const char*'. So I call:
returnedValue = [[[NSCalendarDate alloc] dateWithCalendarFormat:[NSString stringWithUTF8String:data] timeZone:nil]autorelease];
What do you mean with "that's not right"? Why not?
* Always, and only, call an "initXXX" method on the returned value from an alloc method. The init method used also needs to be one of the documented designated initializers for the class!
* -[NSDate dateWithCalendarFormat:timeZone:] is an instance method of NSDate, to convert a NSDate instance into a NSCalendarDate instance. It's not a designated initializer for the NSCalendarDate class!
Oh man! What a silly mistake. Of course!...
You should probably do:
NSString *dateStr = [NSString stringWithUTF8String: data];
NSCalendarDate *aDate = [NSCalendarDate dateWithString: dateStr calendarFormat: nil];
Hum... doesn't work:
const char *data = "2004-11-15 10:46:07 +0100";
NSCalendarDate *newDate = [NSCalendarDate dateWithString: [NSString stringWithUTF8String: data] calendarFormat: nil];
NSLog(@"newDate: %@", newDate);
Shows:
NSScanner: nil string argument
newDate: 2004-01-01 00:00:00 +0100
If I use NSCalendarDate *newDate = [NSCalendarDate dateWithString: [NSString stringWithUTF8String: data]];, it works fine.
Thanks again,
-- Tito
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden