Annotation of Examples/EnterpriseObjects/Validation/Validation.subproj/KeyValueValidation.m, revision 1.1

1.1     ! root        1: #import "KeyValueValidation.h"
        !             2: 
        !             3: static NSDictionary *validateValuesInDictionary(id object, NSDictionary *values)
        !             4: {
        !             5:     NSEnumerator *editEnum = [values keyEnumerator];
        !             6:     NSMutableDictionary *errorDict = nil;
        !             7:     NSString *key;
        !             8: 
        !             9:     while (key = [editEnum nextObject]) {
        !            10:         // construct a selector and see if the have a validation method
        !            11:         id value = [values objectForKey:key];
        !            12:         NSString *methodName = [NSString stringWithFormat:@"validate%@:", [key capitalizedString]];
        !            13:         SEL selector = sel_getUid([methodName cString]);
        !            14:         NSString *errorMessage = nil;
        !            15: 
        !            16:         if (selector && [object respondsToSelector:selector]) {
        !            17:             errorMessage = [object perform:selector withObject:value];
        !            18:             if (errorMessage) {
        !            19:                 if (!errorDict)
        !            20:                     errorDict = [NSMutableDictionary dictionary];
        !            21:                 [errorDict setObject:errorMessage forKey:key];
        !            22:             }
        !            23:         }
        !            24:     }
        !            25:     return errorDict;
        !            26: }
        !            27: 
        !            28: @implementation NSObject (KeyValueValidation)
        !            29: - (NSDictionary *)validateValuesInDictionary:(NSDictionary *)values
        !            30: {
        !            31:     return validateValuesInDictionary(self, values);
        !            32: }
        !            33: @end
        !            34: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.