• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Subclassing NSDateFormatter problem
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Subclassing NSDateFormatter problem


  • Subject: Subclassing NSDateFormatter problem
  • From: Luca Torella <email@hidden>
  • Date: Mon, 20 Sep 2004 17:44:39 +0200

Hi,
I subclassed NSDateFormatter since I had the following problem. I've got a table view where an user can insert in one specific column time. Not clock time but duration time. For example 1:12:13 means 1 hr 12 min and 13 sec. And until that no problems since I could use a simply nsdateformatter instance. But I'd like that when the user digit 1:23 it means 0:1:23, not 1:23:0 like the normal formatter does.

I've attached the code of the subclass. When I run the code I take the following error:

-[NSCalendarDate length]: selector not recognized

Do you know where's the problem?

Thx,
Luca.


- (id *)obj forString:(NSString *)string errorDescription:(NSString **)error
{
NSScanner *scanner = [NSScanner scannerWithString: strin];


int n[3] = {0};
int i = 0;
BOOL retval = YES;


while ( ![scanner isAtEnd] ) {
if (![scanner scanInt: &n[i]]) {
*error = @"Data format not valid";
retval = NO;
}
[scanner scanString:@":" intoString: nil];
i++;
}


switch (i) {
case 1:
*obj = [NSCalendarDate
dateWithString:[NSString stringWithFormat: @"0:%d:0", n[0]]

calendarFormat:@"%H:%M:%S"];
break;
case 2:
*obj = [NSCalendarDate
dateWithString:[NSString stringWithFormat: @"0:%d:%d", n[1], n[0]]

calendarFormat:@"%H:%M:%S"];
break;
case 3:
*obj = [NSCalendarDate
dateWithString:[NSString stringWithFormat: @"%d:%d:%d", n[2], n[1], n[0]]

calendarFormat:@"%H:%M:%S"];
break;
default:
retval = NO;
}
return retval;
}

- (NSString *)stringForObjectValue:(id)anObject
{
if (![anObject isKindOfClass:[NSCalendarDate class]]) {
return nil;
}
return anObject;
}
 _______________________________________________
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

  • Follow-Ups:
    • Re: Subclassing NSDateFormatter problem
      • From: Frederick Cheung <email@hidden>
  • Prev by Date: Re: Bindings: how to deal with canRemove ?
  • Next by Date: Re: Subclassing NSDateFormatter problem
  • Previous by thread: Re: Bug in NSTextField?
  • Next by thread: Re: Subclassing NSDateFormatter problem
  • Index(es):
    • Date
    • Thread