File:  [NeXTSTEP 3.3 examples] / Examples / EnterpriseObjects / Validation / Validation.subproj / KeyValueValidation.m
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Tue Apr 24 17:48:57 2018 UTC (8 years, 1 month ago) by root
Branches: NeXT, MAIN
CVS tags: NeXTSTEP33, HEAD
Sample Programs from NeXSTEP 3.3

#import "KeyValueValidation.h"

static NSDictionary *validateValuesInDictionary(id object, NSDictionary *values)
{
    NSEnumerator *editEnum = [values keyEnumerator];
    NSMutableDictionary *errorDict = nil;
    NSString *key;

    while (key = [editEnum nextObject]) {
        // construct a selector and see if the have a validation method
        id value = [values objectForKey:key];
        NSString *methodName = [NSString stringWithFormat:@"validate%@:", [key capitalizedString]];
        SEL selector = sel_getUid([methodName cString]);
        NSString *errorMessage = nil;

        if (selector && [object respondsToSelector:selector]) {
            errorMessage = [object perform:selector withObject:value];
            if (errorMessage) {
                if (!errorDict)
                    errorDict = [NSMutableDictionary dictionary];
                [errorDict setObject:errorMessage forKey:key];
            }
        }
    }
    return errorDict;
}

@implementation NSObject (KeyValueValidation)
- (NSDictionary *)validateValuesInDictionary:(NSDictionary *)values
{
    return validateValuesInDictionary(self, values);
}
@end


unix.superglobalmegacorp.com

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