Skip to content

Commit

Permalink
replace objc json key name to const key name
Browse files Browse the repository at this point in the history
  • Loading branch information
minaisland committed Jan 15, 2016
1 parent de86142 commit 56af5b3
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 33 deletions.
3 changes: 2 additions & 1 deletion JSONExport/FileRepresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ class FileRepresenter{

}
propertyHandlingStr = propertyHandlingStr.stringByReplacingOccurrencesOfString(varName, withString:property.nativeName)

propertyHandlingStr = propertyHandlingStr.stringByReplacingOccurrencesOfString(constKeyName, withString:property.constName!)
propertyHandlingStr = propertyHandlingStr.stringByReplacingOccurrencesOfString(varType, withString:property.type)

propertyHandlingStr = propertyHandlingStr.stringByReplacingOccurrencesOfString(jsonKeyName, withString:property.jsonName)
Expand Down Expand Up @@ -432,6 +432,7 @@ class FileRepresenter{
//Apply all the basic replacements
propertyStr = propertyStr.stringByReplacingOccurrencesOfString(varName, withString: property.nativeName)
propertyStr = propertyStr.stringByReplacingOccurrencesOfString(jsonKeyName, withString: property.jsonName)
propertyStr = propertyStr.stringByReplacingOccurrencesOfString(constKeyName, withString: property.constName!)
propertyStr = propertyStr.stringByReplacingOccurrencesOfString(varType, withString: property.type)
let capVarName = property.nativeName.capitalizedString
let capVarType = property.type.capitalizedString;
Expand Down
32 changes: 16 additions & 16 deletions JSONExport/Supported Languages/ObjectiveC-Mac.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@
"signature": "\n-(instancetype)initWithDictionary:(NSDictionary *)dictionary\n",
"bodyStart": "{\n\tself = [super init];",
"bodyEnd": "\n\treturn self;\n}\n",
"fetchBasicTypePropertyFromMap": "\n\tif(![dictionary[@\"<!JsonKeyName!>\"] isKindOfClass:[NSNull class]]){\n\t\tself.<!VarName!> = dictionary[@\"<!JsonKeyName!>\"];\n\t}\n",
"fetchBasicTypeWithSpecialNeedsPropertyFromMap": "\n\tif(![dictionary[@\"<!JsonKeyName!>\"] isKindOfClass:[NSNull class]]){\n\t\tself.<!VarName!> = [dictionary[@\"<!JsonKeyName!>\"] <!VarBasicTypeReplacement!>];\n\t}\n",
"fetchCustomTypePropertyFromMap": "\n\tif(![dictionary[@\"<!JsonKeyName!>\"] isKindOfClass:[NSNull class]]){\n\t\tself.<!VarName!> = [[<!VarType!> alloc] initWithDictionary:dictionary[@\"<!JsonKeyName!>\"]];\n\t}\n",
"fetchArrayOfCustomTypePropertyFromMap": "\n\tif(dictionary[@\"<!JsonKeyName!>\"] != nil && [dictionary[@\"<!JsonKeyName!>\"] isKindOfClass:[NSArray class]]){\n\t\tNSArray * <!VarName!>Dictionaries = dictionary[@\"<!JsonKeyName!>\"];\n\t\tNSMutableArray * <!VarName!>Items = [NSMutableArray array];\n\t\tfor(NSDictionary * <!VarName!>Dictionary in <!VarName!>Dictionaries){\n\t\t\t<!ElementType!> * <!VarName!>Item = [[<!ElementType!> alloc] initWithDictionary:<!VarName!>Dictionary];\n\t\t\t[<!VarName!>Items addObject:<!VarName!>Item];\n\t\t}\n\t\tself.<!VarName!> = <!VarName!>Items;\n\t}"
"fetchBasicTypePropertyFromMap": "\n\tif(![dictionary[<!ConstKeyName!>] isKindOfClass:[NSNull class]]){\n\t\tself.<!VarName!> = dictionary[<!ConstKeyName!>];\n\t}\n",
"fetchBasicTypeWithSpecialNeedsPropertyFromMap": "\n\tif(![dictionary[<!ConstKeyName!>] isKindOfClass:[NSNull class]]){\n\t\tself.<!VarName!> = [dictionary[<!ConstKeyName!>] <!VarBasicTypeReplacement!>];\n\t}\n",
"fetchCustomTypePropertyFromMap": "\n\tif(![dictionary[<!ConstKeyName!>] isKindOfClass:[NSNull class]]){\n\t\tself.<!VarName!> = [[<!VarType!> alloc] initWithDictionary:dictionary[<!ConstKeyName!>]];\n\t}\n",
"fetchArrayOfCustomTypePropertyFromMap": "\n\tif(dictionary[<!ConstKeyName!>] != nil && [dictionary[<!ConstKeyName!>] isKindOfClass:[NSArray class]]){\n\t\tNSArray * <!VarName!>Dictionaries = dictionary[<!ConstKeyName!>];\n\t\tNSMutableArray * <!VarName!>Items = [NSMutableArray array];\n\t\tfor(NSDictionary * <!VarName!>Dictionary in <!VarName!>Dictionaries){\n\t\t\t<!ElementType!> * <!VarName!>Item = [[<!ElementType!> alloc] initWithDictionary:<!VarName!>Dictionary];\n\t\t\t[<!VarName!>Items addObject:<!VarName!>Item];\n\t\t}\n\t\tself.<!VarName!> = <!VarName!>Items;\n\t}"
}
],
"utilityMethods": [
Expand All @@ -98,31 +98,31 @@
"bodyStart": "\n{\n",
"bodyEnd": "\n}\n",
"body": "\tNSMutableDictionary * dictionary = [NSMutableDictionary dictionary];\n",
"forEachPropertyWithSpecialStoringNeeds": "\tdictionary[@\"<!JsonKeyName!>\"] = @(self.<!VarName!>);\n",
"forEachProperty": "\tif(self.<!VarName!> != nil){\n\t\tdictionary[@\"<!JsonKeyName!>\"] = self.<!VarName!>;\n\t}\n",
"forEachCustomTypeProperty": "\tif(self.<!VarName!> != nil){\n\t\tdictionary[@\"<!JsonKeyName!>\"] = [self.<!VarName!> toDictionary];\n\t}\n",
"forEachArrayOfCustomTypeProperty": "\tif(self.<!VarName!> != nil){\n\t\tNSMutableArray * dictionaryElements = [NSMutableArray array];\n\t\tfor(<!ElementType!> * <!VarName!>Element in self.<!VarName!>){\n\t\t\t[dictionaryElements addObject:[<!VarName!>Element toDictionary]];\n\t\t}\n\t\tdictionary[@\"<!JsonKeyName!>\"] = dictionaryElements;\n\t}\n",
"forEachPropertyWithSpecialStoringNeeds": "\tdictionary[<!ConstKeyName!>] = @(self.<!VarName!>);\n",
"forEachProperty": "\tif(self.<!VarName!> != nil){\n\t\tdictionary[<!ConstKeyName!>] = self.<!VarName!>;\n\t}\n",
"forEachCustomTypeProperty": "\tif(self.<!VarName!> != nil){\n\t\tdictionary[<!ConstKeyName!>] = [self.<!VarName!> toDictionary];\n\t}\n",
"forEachArrayOfCustomTypeProperty": "\tif(self.<!VarName!> != nil){\n\t\tNSMutableArray * dictionaryElements = [NSMutableArray array];\n\t\tfor(<!ElementType!> * <!VarName!>Element in self.<!VarName!>){\n\t\t\t[dictionaryElements addObject:[<!VarName!>Element toDictionary]];\n\t\t}\n\t\tdictionary[<!ConstKeyName!>] = dictionaryElements;\n\t}\n",
"returnStatement": "\treturn dictionary;\n"
},
{
"forEachProperty": "\tif(self.<!VarName!> != nil){\n\t\t[aCoder encodeObject:self.<!VarName!> forKey:@\"<!JsonKeyName!>\"];\n\t}\n",
"forEachProperty": "\tif(self.<!VarName!> != nil){\n\t\t[aCoder encodeObject:self.<!VarName!> forKey:<!ConstKeyName!>];\n\t}\n",
"bodyEnd": "\n}\n",
"signature": "- (void)encodeWithCoder:(NSCoder *)aCoder",
"forEachPropertyWithSpecialStoringNeeds": "\t[aCoder encodeObject:@(self.<!VarName!>) forKey:@\"<!JsonKeyName!>\"];",
"forEachArrayOfCustomTypeProperty": "\tif(self.<!VarName!> != nil){\n\t\t[aCoder encodeObject:self.<!VarName!> forKey:@\"<!JsonKeyName!>\"];\n\t}\n",
"forEachCustomTypeProperty": "\tif(self.<!VarName!> != nil){\n\t\t[aCoder encodeObject:self.<!VarName!> forKey:@\"<!JsonKeyName!>\"];\n\t}\n",
"forEachPropertyWithSpecialStoringNeeds": "\t[aCoder encodeObject:@(self.<!VarName!>) forKey:<!ConstKeyName!>];",
"forEachArrayOfCustomTypeProperty": "\tif(self.<!VarName!> != nil){\n\t\t[aCoder encodeObject:self.<!VarName!> forKey:<!ConstKeyName!>];\n\t}\n",
"forEachCustomTypeProperty": "\tif(self.<!VarName!> != nil){\n\t\t[aCoder encodeObject:self.<!VarName!> forKey:<!ConstKeyName!>];\n\t}\n",
"returnStatement": "",
"body": "",
"comment": "\n/**\n * Implementation of NSCoding encoding method\n */\n/**\n * Returns all the available property values in the form of NSDictionary object where the key is the approperiate json key and the value is the value of the corresponding property\n */\n",
"bodyStart": "\n{\n"
},
{
"forEachProperty": "\tself.<!VarName!> = [aDecoder decodeObjectForKey:@\"<!JsonKeyName!>\"];\n",
"forEachProperty": "\tself.<!VarName!> = [aDecoder decodeObjectForKey:<!ConstKeyName!>];\n",
"bodyEnd": "\n}\n",
"signature": "- (instancetype)initWithCoder:(NSCoder *)aDecoder",
"forEachPropertyWithSpecialStoringNeeds": "\tself.<!VarName!> = [[aDecoder decodeObjectForKey:@\"<!JsonKeyName!>\"] <!VarBasicTypeReplacement!>];\n",
"forEachArrayOfCustomTypeProperty": "\tself.<!VarName!> = [aDecoder decodeObjectForKey:@\"<!JsonKeyName!>\"];\n",
"forEachCustomTypeProperty": "\tself.<!VarName!> = [aDecoder decodeObjectForKey:@\"<!JsonKeyName!>\"];\n",
"forEachPropertyWithSpecialStoringNeeds": "\tself.<!VarName!> = [[aDecoder decodeObjectForKey:<!ConstKeyName!>] <!VarBasicTypeReplacement!>];\n",
"forEachArrayOfCustomTypeProperty": "\tself.<!VarName!> = [aDecoder decodeObjectForKey:<!ConstKeyName!>];\n",
"forEachCustomTypeProperty": "\tself.<!VarName!> = [aDecoder decodeObjectForKey:<!ConstKeyName!>];\n",
"returnStatement": "\treturn self;\n",
"body": "\tself = [super init];\n",
"comment": "\n/**\n * Implementation of NSCoding initWithCoder: method\n */\n",
Expand Down
33 changes: 17 additions & 16 deletions JSONExport/Supported Languages/ObjectiveC-iOS.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,36 +80,36 @@
"briefDescription": "Defines how your JSON objects can be mapped to Objective-c classes using the built-in NSJSONSerialization class",
"utilityMethods": [
{
"forEachProperty": "\tif(self.<!VarName!> != nil){\n\t\tdictionary[@\"<!JsonKeyName!>\"] = self.<!VarName!>;\n\t}\n",
"forEachProperty": "\tif(self.<!VarName!> != nil){\n\t\tdictionary[<!ConstKeyName!>] = self.<!VarName!>;\n\t}\n",
"bodyEnd": "\n}\n",
"signature": "-(NSDictionary *)toDictionary",
"forEachPropertyWithSpecialStoringNeeds": "\tdictionary[@\"<!JsonKeyName!>\"] = @(self.<!VarName!>);\n",
"forEachArrayOfCustomTypeProperty": "\tif(self.<!VarName!> != nil){\n\t\tNSMutableArray * dictionaryElements = [NSMutableArray array];\n\t\tfor(<!ElementType!> * <!VarName!>Element in self.<!VarName!>){\n\t\t\t[dictionaryElements addObject:[<!VarName!>Element toDictionary]];\n\t\t}\n\t\tdictionary[@\"<!JsonKeyName!>\"] = dictionaryElements;\n\t}\n",
"forEachCustomTypeProperty": "\tif(self.<!VarName!> != nil){\n\t\tdictionary[@\"<!JsonKeyName!>\"] = [self.<!VarName!> toDictionary];\n\t}\n",
"forEachPropertyWithSpecialStoringNeeds": "\tdictionary[<!ConstKeyName!>] = @(self.<!VarName!>);\n",
"forEachArrayOfCustomTypeProperty": "\tif(self.<!VarName!> != nil){\n\t\tNSMutableArray * dictionaryElements = [NSMutableArray array];\n\t\tfor(<!ElementType!> * <!VarName!>Element in self.<!VarName!>){\n\t\t\t[dictionaryElements addObject:[<!VarName!>Element toDictionary]];\n\t\t}\n\t\tdictionary[<!ConstKeyName!>] = dictionaryElements;\n\t}\n",
"forEachCustomTypeProperty": "\tif(self.<!VarName!> != nil){\n\t\tdictionary[<!ConstKeyName!>] = [self.<!VarName!> toDictionary];\n\t}\n",
"returnStatement": "\treturn dictionary;\n",
"body": "\tNSMutableDictionary * dictionary = [NSMutableDictionary dictionary];\n",
"comment": "\n/**\n * Returns all the available property values in the form of NSDictionary object where the key is the approperiate json key and the value is the value of the corresponding property\n */\n",
"bodyStart": "\n{\n"
},
{
"forEachProperty": "\tif(self.<!VarName!> != nil){\n\t\t[aCoder encodeObject:self.<!VarName!> forKey:@\"<!JsonKeyName!>\"];\n\t}\n",
"forEachProperty": "\tif(self.<!VarName!> != nil){\n\t\t[aCoder encodeObject:self.<!VarName!> forKey:<!ConstKeyName!>];\n\t}\n",
"bodyEnd": "\n}\n",
"signature": "- (void)encodeWithCoder:(NSCoder *)aCoder",
"forEachPropertyWithSpecialStoringNeeds": "\t[aCoder encodeObject:@(self.<!VarName!>) forKey:@\"<!JsonKeyName!>\"];",
"forEachArrayOfCustomTypeProperty": "\tif(self.<!VarName!> != nil){\n\t\t[aCoder encodeObject:self.<!VarName!> forKey:@\"<!JsonKeyName!>\"];\n\t}\n",
"forEachCustomTypeProperty": "\tif(self.<!VarName!> != nil){\n\t\t[aCoder encodeObject:self.<!VarName!> forKey:@\"<!JsonKeyName!>\"];\n\t}\n",
"forEachPropertyWithSpecialStoringNeeds": "\t[aCoder encodeObject:@(self.<!VarName!>) forKey:<!ConstKeyName!>];",
"forEachArrayOfCustomTypeProperty": "\tif(self.<!VarName!> != nil){\n\t\t[aCoder encodeObject:self.<!VarName!> forKey:<!ConstKeyName!>];\n\t}\n",
"forEachCustomTypeProperty": "\tif(self.<!VarName!> != nil){\n\t\t[aCoder encodeObject:self.<!VarName!> forKey:<!ConstKeyName!>];\n\t}\n",
"returnStatement": "",
"body": "",
"comment": "\n/**\n * Implementation of NSCoding encoding method\n */\n/**\n * Returns all the available property values in the form of NSDictionary object where the key is the approperiate json key and the value is the value of the corresponding property\n */\n",
"bodyStart": "\n{\n"
},
{
"forEachProperty": "\tself.<!VarName!> = [aDecoder decodeObjectForKey:@\"<!JsonKeyName!>\"];\n",
"forEachProperty": "\tself.<!VarName!> = [aDecoder decodeObjectForKey:<!ConstKeyName!>];\n",
"bodyEnd": "\n}\n",
"signature": "- (instancetype)initWithCoder:(NSCoder *)aDecoder",
"forEachPropertyWithSpecialStoringNeeds": "\tself.<!VarName!> = [[aDecoder decodeObjectForKey:@\"<!JsonKeyName!>\"] <!VarBasicTypeReplacement!>];\n",
"forEachArrayOfCustomTypeProperty": "\tself.<!VarName!> = [aDecoder decodeObjectForKey:@\"<!JsonKeyName!>\"];\n",
"forEachCustomTypeProperty": "\tself.<!VarName!> = [aDecoder decodeObjectForKey:@\"<!JsonKeyName!>\"];\n",
"forEachPropertyWithSpecialStoringNeeds": "\tself.<!VarName!> = [[aDecoder decodeObjectForKey:<!ConstKeyName!>] <!VarBasicTypeReplacement!>];\n",
"forEachArrayOfCustomTypeProperty": "\tself.<!VarName!> = [aDecoder decodeObjectForKey:<!ConstKeyName!>];\n",
"forEachCustomTypeProperty": "\tself.<!VarName!> = [aDecoder decodeObjectForKey:<!ConstKeyName!>];\n",
"returnStatement": "\treturn self;\n",
"body": "\tself = [super init];\n",
"comment": "\n/**\n * Implementation of NSCoding initWithCoder: method\n */\n",
Expand Down Expand Up @@ -143,16 +143,17 @@
],
"constructors": [
{
"fetchBasicTypeWithSpecialNeedsPropertyFromMap": "\n\tif(![dictionary[@\"<!JsonKeyName!>\"] isKindOfClass:[NSNull class]]){\n\t\tself.<!VarName!> = [dictionary[@\"<!JsonKeyName!>\"] <!VarBasicTypeReplacement!>];\n\t}\n",
"fetchCustomTypePropertyFromMap": "\n\tif(![dictionary[@\"<!JsonKeyName!>\"] isKindOfClass:[NSNull class]]){\n\t\tself.<!VarName!> = [[<!VarType!> alloc] initWithDictionary:dictionary[@\"<!JsonKeyName!>\"]];\n\t}\n",
"fetchBasicTypeWithSpecialNeedsPropertyFromMap": "\n\tif(![dictionary[<!ConstKeyName!>] isKindOfClass:[NSNull class]]){\n\t\tself.<!VarName!> = [dictionary[<!ConstKeyName!>] <!VarBasicTypeReplacement!>];\n\t}\n",
"fetchCustomTypePropertyFromMap": "\n\tif(![dictionary[<!ConstKeyName!>] isKindOfClass:[NSNull class]]){\n\t\tself.<!VarName!> = [[<!VarType!> alloc] initWithDictionary:dictionary[<!ConstKeyName!>]];\n\t}\n",
"bodyEnd": "\n\treturn self;\n}\n",
"fetchBasicTypePropertyFromMap": "\n\tif(![dictionary[@\"<!JsonKeyName!>\"] isKindOfClass:[NSNull class]]){\n\t\tself.<!VarName!> = dictionary[@\"<!JsonKeyName!>\"];\n\t}\t",
"fetchBasicTypePropertyFromMap": "\n\tif(![dictionary[<!ConstKeyName!>] isKindOfClass:[NSNull class]]){\n\t\tself.<!VarName!> = dictionary[<!ConstKeyName!>];\n\t}\t",
"signature": "\n-(instancetype)initWithDictionary:(NSDictionary *)dictionary\n",
"fetchArrayOfCustomTypePropertyFromMap": "\n\tif(dictionary[@\"<!JsonKeyName!>\"] != nil && [dictionary[@\"<!JsonKeyName!>\"] isKindOfClass:[NSArray class]]){\n\t\tNSArray * <!VarName!>Dictionaries = dictionary[@\"<!JsonKeyName!>\"];\n\t\tNSMutableArray * <!VarName!>Items = [NSMutableArray array];\n\t\tfor(NSDictionary * <!VarName!>Dictionary in <!VarName!>Dictionaries){\n\t\t\t<!ElementType!> * <!VarName!>Item = [[<!ElementType!> alloc] initWithDictionary:<!VarName!>Dictionary];\n\t\t\t[<!VarName!>Items addObject:<!VarName!>Item];\n\t\t}\n\t\tself.<!VarName!> = <!VarName!>Items;\n\t}",
"fetchArrayOfCustomTypePropertyFromMap": "\n\tif(dictionary[<!ConstKeyName!>] != nil && [dictionary[<!ConstKeyName!>] isKindOfClass:[NSArray class]]){\n\t\tNSArray * <!VarName!>Dictionaries = dictionary[<!ConstKeyName!>];\n\t\tNSMutableArray * <!VarName!>Items = [NSMutableArray array];\n\t\tfor(NSDictionary * <!VarName!>Dictionary in <!VarName!>Dictionaries){\n\t\t\t<!ElementType!> * <!VarName!>Item = [[<!ElementType!> alloc] initWithDictionary:<!VarName!>Dictionary];\n\t\t\t[<!VarName!>Items addObject:<!VarName!>Item];\n\t\t}\n\t\tself.<!VarName!> = <!VarName!>Items;\n\t}",
"comment": "\n/**\n * Instantiate the instance using the passed dictionary values to set the properties values\n */\n",
"bodyStart": "{\n\tself = [super init];"
}
],
"constVarDefinition": "NSString *const <!ConstKeyName!> = @\"<!JsonKeyName!>\";\n",
"modelDefinition": "\n@interface <!ModelName!> ()\n@end\n@implementation <!ModelName!>\n",
"genericType": "NSObject",
"headerFileData": {
Expand Down

0 comments on commit 56af5b3

Please sign in to comment.