tags:

views:

398

answers:

1

Is it necessary that i have to write the following method to call it in the if....part.

-(NSComparisonResult) compare:(NSDate *)expDate{}

if yes, then how and where i have to write this method so that the following code will work fine?

if (licenseDictionary == nil)
    return @"Not Registered";
else if([today compare:expDate] == NSOrderedAscending)
{   
    [gotoButton setEnabled:YES];
    return [licenseDictionary objectForKey:@"Name"];
}
else
    return @"License Expired";
+6  A: 

There are also earlierDate: and laterDate: and isEqualToDate:.

You can find the documentation on them here.

So something like:

if ([today laterDate:expDate] == expDate)

That's dry-coded here in the browser, but I think that's what you'd want.

EDIT: I fixed a typo in the above, you don't need to use compare:. laterDate: and earlierDate: handle the comparisons and return the object that is later or earlier respectively.

So the above code says which one is later, today or expDate, and if expDate is the later one (pointer comparison should work here I think, but if not try isEqualToDate: instead) then it hasn't expired yet and their license should be valid.

I hope that helps make more sense.

Bryan McLemore
thanks Bryan, but i have already gone thro' this. is der any other way?
Shakti
what exactly is your objection to using the built-in methods of NSDate to test this?
NSResponder
actually, i m not able to know how to provide a reciever date to compare method i have a expDate variable, i m getting the date for this from a plist file. my question is it necessary to write a (NSComparisonResult) compare:(NSDate *)expDate method. how and where?
Shakti
@Shakti, I've updated my description some to give more explanation. I'm ~ 99% sure that the above if statement, or some slight variation of it, is what you're needing.
Bryan McLemore
@Shakti, as I answered your other question http://stackoverflow.com/questions/1811779/comparing-dates-in-cocoa. If you just store the date in the plist as an NSDate object your problems will go away.
Abizern