@@ -0,0 +1,1602 @@
+import sys%0Aimport os.path%0Aimport re%0A%0Aif 2 != len(sys.argv) or sys.argv%5B1%5D%5B-2:%5D != '.h':%0A    print %22usage: %25s %3CClassHeader.h%3E%22 %25 os.path.basename(sys.argv%5B0%5D)%0A    print%0A    print %22Given an class header file, extract the properties and generate an NSCoding implementation.%22%0A    sys.exit(1)%0A%0APROPERTY_MATCHER = re.compile(r'%5C@property *(%5C(.*%5C))? *(?P%3Ctype%3E.*) +%5C*?(?P%3Cname%3E.*);')%0A%0A%0Adef encoderForClass(klass):%0A    if klass in ('bool', 'BOOL'):%0A        return 'encodeBool'%0A    return 'encodeObject'%0A%0A%0Adef decoderForClass(klass):%0A    if klass in ('bool', 'BOOL'):%0A        return 'decodeBoolForKey'%0A    return 'decodeObjectForKey'%0A%0A%0Aprops = %5B%5D%0Awith open(sys.argv%5B1%5D, 'rb') as handle:%0A    for line in handle:%0A        match = PROPERTY_MATCHER.search(line)%0A        if match:%0A            props.append(%7B%0A                %22class%22: match.group('type'),%0A                %22name%22: match.group('name'),%0A                %22keyName%22: match.group('name')%5B0%5D.upper() + match.group('name')%5B1:%5D,%0A                %22encoder%22: encoderForClass(match.group('type')),%0A                %22decoder%22: decoderForClass(match.group('type'))%0A            %7D)%0A%0Aprint %22#pragma mark - NSCoding%22%0Aprint%0A%0Afor prop in props:%0A    print '#define k%25(keyName)s  @%22%25(keyName)s%22' %25 prop%0A%0Aprint%0Aprint '- (void)encodeWithCoder:(NSCoder *)encoder %7B'%0A%0Afor prop in props:%0A    print '    %5Bencoder %25(encoder)s forKey:k%25(keyName)s%5D;' %25 prop%0A%0Aprint '%7D'%0Aprint%0A%0Aprint '- (id)initWithCoder:(NSCoder *)decoder %7B'%0Aprint '    self = %5Bself init%5D;'%0Afor prop in props:%0A    print '    self.%25(name)s = %5Bdecoder %25(decoder)s:k%25(keyName)s%5D;' %25 prop%0Aprint '    return self;'%0Aprint '%7D'%0A

Add NSCoding implementation generator.