Skip to content

Commit

Permalink
Fixed small bug when writing double quotes by hand.
Browse files Browse the repository at this point in the history
Added support for Realm with Objective-C
  • Loading branch information
Ahmed-Ali committed Dec 6, 2014
1 parent f0861c5 commit 2f8f942
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 6 deletions.
4 changes: 4 additions & 0 deletions JSONExport.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
E23C7E611A17CAC50009B9E5 /* SwiftyJSON-Class.json in Resources */ = {isa = PBXBuildFile; fileRef = E23C7E601A17CAC50009B9E5 /* SwiftyJSON-Class.json */; };
E23C7E631A17CAF50009B9E5 /* Swift-Struct.json in Resources */ = {isa = PBXBuildFile; fileRef = E23C7E621A17CAF50009B9E5 /* Swift-Struct.json */; };
E2502B2F1A2894E800A77A5D /* Swift-CoreData.json in Resources */ = {isa = PBXBuildFile; fileRef = E2502B2E1A2894E800A77A5D /* Swift-CoreData.json */; };
E27421D91A334165009685AD /* Realm-ObjectiveC.json in Resources */ = {isa = PBXBuildFile; fileRef = E27421D81A334165009685AD /* Realm-ObjectiveC.json */; };
E278F9C61A2149AC00306EFC /* HeaderFileData.swift in Sources */ = {isa = PBXBuildFile; fileRef = E278F9C51A2149AC00306EFC /* HeaderFileData.swift */; };
E278F9C81A214FF000306EFC /* ObjectiveC-iOS.json in Resources */ = {isa = PBXBuildFile; fileRef = E278F9C71A214FF000306EFC /* ObjectiveC-iOS.json */; };
E278F9CA1A2152D800306EFC /* HeaderFileRepresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = E278F9C91A2152D800306EFC /* HeaderFileRepresenter.swift */; };
Expand Down Expand Up @@ -50,6 +51,7 @@
E23C7E601A17CAC50009B9E5 /* SwiftyJSON-Class.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = "SwiftyJSON-Class.json"; path = "PredefinedLanguages/SwiftyJSON-Class.json"; sourceTree = "<group>"; };
E23C7E621A17CAF50009B9E5 /* Swift-Struct.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = "Swift-Struct.json"; path = "PredefinedLanguages/Swift-Struct.json"; sourceTree = "<group>"; };
E2502B2E1A2894E800A77A5D /* Swift-CoreData.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = "Swift-CoreData.json"; path = "PredefinedLanguages/Swift-CoreData.json"; sourceTree = "<group>"; };
E27421D81A334165009685AD /* Realm-ObjectiveC.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "Realm-ObjectiveC.json"; sourceTree = "<group>"; };
E278F9C51A2149AC00306EFC /* HeaderFileData.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HeaderFileData.swift; sourceTree = "<group>"; };
E278F9C71A214FF000306EFC /* ObjectiveC-iOS.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = "ObjectiveC-iOS.json"; path = "PredefinedLanguages/ObjectiveC-iOS.json"; sourceTree = "<group>"; };
E278F9C91A2152D800306EFC /* HeaderFileRepresenter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HeaderFileRepresenter.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -137,6 +139,7 @@
children = (
E2193D051A1292A200138A29 /* Java-Android.json */,
E278F9C71A214FF000306EFC /* ObjectiveC-iOS.json */,
E27421D81A334165009685AD /* Realm-ObjectiveC.json */,
E2DEAE9A1A2295E80001818B /* ObjectiveC-Mac.json */,
E2D930C11A2661350014B195 /* ObjectiveC-CoreData-iOS.json */,
E2F07E8B1A0B31C3004A1DAA /* Swift-Class.json */,
Expand Down Expand Up @@ -257,6 +260,7 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
E27421D91A334165009685AD /* Realm-ObjectiveC.json in Resources */,
E2D930C21A2661350014B195 /* ObjectiveC-CoreData-iOS.json in Resources */,
E2DEAE9B1A2295E80001818B /* ObjectiveC-Mac.json in Resources */,
E23C7E611A17CAC50009B9E5 /* SwiftyJSON-Class.json in Resources */,
Expand Down
6 changes: 3 additions & 3 deletions JSONExport/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textView importsGraphics="NO" richText="NO" findStyle="panel" continuousSpellChecking="YES" allowsUndo="YES" usesRuler="YES" usesFontPanel="YES" verticallyResizable="YES" allowsNonContiguousLayout="YES" quoteSubstitution="YES" dashSubstitution="YES" spellingCorrection="YES" smartInsertDelete="YES" id="GOY-cO-0Ne">
<rect key="frame" x="0.0" y="0.0" width="223" height="427"/>
<rect key="frame" x="0.0" y="0.0" width="223" height="627"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<size key="minSize" width="360" height="627"/>
Expand Down Expand Up @@ -781,10 +781,10 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<size key="minSize" width="540" height="194"/>
<size key="maxSize" width="542" height="10000000"/>
<size key="maxSize" width="557" height="10000000"/>
<color key="insertionPointColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<size key="minSize" width="540" height="194"/>
<size key="maxSize" width="542" height="10000000"/>
<size key="maxSize" width="557" height="10000000"/>
</textView>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
Expand Down
2 changes: 1 addition & 1 deletion JSONExport/FileContentBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class FilesContentBuilder{
var firstLine = ""

/**
Lazely load and return the singlton instance of the FilesContentBuilder
Lazely load and return the singleton instance of the FilesContentBuilder
*/
class var instance : FilesContentBuilder {
struct Static {
Expand Down
4 changes: 3 additions & 1 deletion JSONExport/FileRepresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,9 @@ class FileRepresenter{
fileContent += " \(organization)"
}

fileContent += ". All rights reserved.\n//\n\n"
fileContent += ". All rights reserved.\n"

fileContent += "//\tModel file Generated using JSONExport: https://github.com/Ahmed-Ali/JSONExport\n\n"

}

Expand Down
87 changes: 87 additions & 0 deletions JSONExport/Realm-ObjectiveC.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
{
"langName": "ObjectiveC-Realm",
"displayLangName": "ObjectiveC - Realm",
"briefDescription": "Defines how your JSON objects can be mapped to Objective-c Realm subclasses using the built-in NSJSONSerialization class",
"fileExtension": "m",
"genericType": "NSObject",
"arrayType": "RLMArray<<!ElementType!>>",
"dataTypes": {
"intType": "NSInteger",
"boolType": "BOOL",
"characterType": "int",
"floatType": "float",
"longType": "long",
"doubleType": "double",
"stringType": "NSString"
},
"supportsFirstLineStatement": "false",
"supportMutualRelationships" : "true",
"staticImports": "",
"importForEachCustomType": "#import \"<!ModelName!>.h\"\n",
"importHeaderFile": "#import \"<!ModelName!>.h\"\n",
"modelDefinition": "\n@interface <!ModelName!> ()\n@end\n@implementation <!ModelName!>\n",
"modelStart": "",
"modelEnd": "@end",
"instanceVarDefinition": "",
"hasHeaderFile": true,
"headerFileData": {
"staticImports": "#import <Realm/Realm.h>",
"importForEachCustomType": "RLM_ARRAY_TYPE(<!ModelName!>)\n@class <!ModelName!>;\n",
"modelDefinition": "\n@interface <!ModelName!> : RLMObject\n",
"modelStart": "",
"modelEnd": "@end",
"instanceVarDefinition": "@property (nonatomic) <!VarType!> * <!VarName!>;\n",
"instanceVarWithSpeicalDefinition": "@property (nonatomic) <!VarType!> <!VarName!>;\n",
"typesNeedSpecialDefinition" : [
"NSInteger",
"BOOL",
"int",
"float",
"double",
"long"
],

"headerFileExtension": "h",
"constructorSignatures": [],
"utilityMethodSignatures": [
"-(NSDictionary *)toDictionary;\n"
]
},
"wordsToRemoveToGetArrayElementsType": [
"RLMArray",
"<",
">"
],
"basicTypesWithSpecialFetchingNeeds": [
"NSInteger",
"BOOL",
"int",
"float",
"double",
"long"
],
"basicTypesWithSpecialFetchingNeedsReplacements": [],
"basicTypesWithSpecialStoringNeeds": [
"NSInteger",
"BOOL",
"int",
"float",
"double",
"long"
],
"constructors": [],
"utilityMethods": [
{
"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",
"signature": "-(NSDictionary *)toDictionary",
"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",
"returnStatement": "\treturn dictionary;\n"
}
]
}
5 changes: 4 additions & 1 deletion JSONExport/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,10 @@ class ViewController: NSViewController, NSUserNotificationCenterDelegate, NSTabl
func generateClasses()
{
saveButton.enabled = false
let str = sourceText.string!
var str = sourceText.string!
str = str.stringByReplacingOccurrencesOfString("", withString: "\"")
str = str.stringByReplacingOccurrencesOfString("", withString: "\"")

if countElements(str) == 0{
//Nothing to do
return;
Expand Down

0 comments on commit 2f8f942

Please sign in to comment.