CoreData validation question

  • Hello list,

    I have the following validation method, why is it not working?

    -(BOOL)validateNumberField2:(id *)ioValue error:(NSError **)outError
    {
    NSNumber *inputNumberField2 = *ioValue;
    NSNumber *numberField2Stat = self.numberField2;
    NSNumber *numberField1Stat = self.numberField1;

    if (numberField2Stat != 0) {
      if (inputNumberField2 <= numberField1Stat) {
      if (outError != NULL) {
        NSString *errorStr = NSLocalizedString(@"Error message.",@"Error message");
        NSDictionary *userInfoDict = [NSDictionary dictionaryWithObject:errorStr      forKey:NSLocalizedDescriptionKey];

        NSError *error = [[[NSError alloc] initWithDomain:kValidationDomain      code:kValidationnumberField2Code userInfo:userInfoDict] autorelease];
        *outError = error;
      }
      return NO;
      }
      return YES;
    }
    return YES;
    }

    What I want is the following:
    The very first object  created in CoreData has the initial value of numberField2 = 0.
    If you enter a new number for this field it has to be larger then the number in numberField1.

    The validation does only work if ,and only if you have already more then 1 object in you CoreData.

    What do I have to change in order to make this validation work:
    If numberField2 has a value of 0, then return yes, else check if inputNumberField2 is smaller than numberField1. If it is smaller, give validation error, else return yes. I think that the logic of the if statement is sound.

    Could someone be so kind and take a look?

    Much appreciated

    Arnold Nefkens
  • On Apr 26, 2010, at 7:51 AM, Arnold Nefkens wrote:

    > Hello list,
    >
    > I have the following validation method, why is it not working?
    >
    > -(BOOL)validateNumberField2:(id *)ioValue error:(NSError **)outError
    > {
    > NSNumber *inputNumberField2 = *ioValue;
    > NSNumber *numberField2Stat = self.numberField2;
    > NSNumber *numberField1Stat = self.numberField1;
    >
    > if (numberField2Stat != 0) {

    QUESTION:  What data type is "numberField2Stat" ?
    ANSWER: it's a POINTER to an NSNumber (not a numeric value).
    therefore it's very likely to never be zero.

    > if (inputNumberField2 <= numberField1Stat) {

    QUESTION:  What data type is "numberField1Stat" ?
    ANSWER: it's a POINTER to an NSNumber (not a numeric value).
    therefore ...... _____ ?

    consider using the intValue of your NSNumbers.

    ----------------------------------------------------------------
    Steve Bird
    Culverson Software - Elegant software that is a pleasure to use.
    www.Culverson.com                    (toll free) 1-877-676-8175
  • Thanks,

    That was just what I needed..... It now works... Thanks again... Sometimes I am a bit lost. Started with iPhone development & Obj-C less then three months ago....
    On 26 apr 2010, at 14:15, Steve Bird wrote:

    >
    > On Apr 26, 2010, at 7:51 AM, Arnold Nefkens wrote:
    >
    >> Hello list,
    >>
    >> I have the following validation method, why is it not working?
    >>
    >> -(BOOL)validateNumberField2:(id *)ioValue error:(NSError **)outError
    >> {
    >> NSNumber *inputNumberField2 = *ioValue;
    >> NSNumber *numberField2Stat = self.numberField2;
    >> NSNumber *numberField1Stat = self.numberField1;
    >>
    >> if (numberField2Stat != 0) {
    >
    > QUESTION:  What data type is "numberField2Stat" ?
    > ANSWER: it's a POINTER to an NSNumber (not a numeric value).
    > therefore it's very likely to never be zero.
    >
    >> if (inputNumberField2 <= numberField1Stat) {
    >
    > QUESTION:  What data type is "numberField1Stat" ?
    > ANSWER: it's a POINTER to an NSNumber (not a numeric value).
    > therefore ...... _____ ?
    >
    > consider using the intValue of your NSNumbers.
    >
    > ----------------------------------------------------------------
    > Steve Bird
    > Culverson Software - Elegant software that is a pleasure to use.
    > www.Culverson.com                    (toll free) 1-877-676-8175
    >
    >
previous month april 2010 next month
MTWTFSS
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30    
Go to today