Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an Swift Codable export with default value supported #143

Open
wants to merge 39 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
d6f592d
Merge pull request #88 from AlexxNica/patch-1
Ahmed-Ali Nov 15, 2017
bf8134e
Merge pull request #96 from kashifshaikh/master
Ahmed-Ali Nov 15, 2017
16893c7
Merge pull request #93 from narlei/master
Ahmed-Ali Nov 15, 2017
c5a4da4
fix a complier error in SwiftyJSON - Class
superk589 Nov 27, 2017
779a06f
Migrate to Swift 4
serhii-londar Dec 13, 2017
e40b258
Added Swift-Codable-Struct with forced unwrapped option
mumer92 Dec 26, 2017
2f8ba42
added back credit file
mumer92 Dec 26, 2017
df54d97
Change generic type from 'AnyObject' to 'String' -> Fixes #105
Feb 12, 2018
8528d6a
Java Gson for Android: Fix method name to be "optString" instead of "…
Mar 3, 2018
02a96ed
Fix: float type issue
Mar 3, 2018
4c61a93
Update to Swift 4.2
BrychanOdlum Oct 2, 2018
0a3d17f
Updating GHANGELOG.md for release 1.0.9
Ahmed-Ali Nov 24, 2018
cdd8a4f
Merge branch 'master' of git://github.com/superk589/JSONExport into s…
Ahmed-Ali Nov 24, 2018
3b306da
Merge branch 'superk589-master' into develop
Ahmed-Ali Nov 24, 2018
30d8785
Updating CHANGELOG.md
Ahmed-Ali Nov 24, 2018
8e804f6
Merge branch 'master' of git://github.com/serhii-londar/JSONExport in…
Ahmed-Ali Nov 24, 2018
8069c92
Merge branch 'serhii-londar-master'
Ahmed-Ali Nov 24, 2018
a45d1ae
Merge branch 'serhii-londar-master' into develop
Ahmed-Ali Nov 24, 2018
c20cabb
Updating CHANGELOG.md
Ahmed-Ali Nov 24, 2018
2c3864f
Merge branch 'master' of git://github.com/mumer92/JSONExport into mum…
Ahmed-Ali Nov 24, 2018
330d94b
Merge branch 'mumer92-master' into develop
Ahmed-Ali Nov 24, 2018
9ca6bdc
Updating CHANGELOG.md
Ahmed-Ali Nov 24, 2018
a9b4ca0
Merge branch 'fix_generic_type_swift_struct_codable' of git://github.…
Ahmed-Ali Nov 24, 2018
870ee94
Merge branch 'ankushkushwaha-fix_generic_type_swift_struct_codable' i…
Ahmed-Ali Nov 24, 2018
0c5bd0d
Updating CHANGELOG.md
Ahmed-Ali Nov 24, 2018
790b7fb
Merge branch 'feature/fix_java_gson_for_android' of git://github.com/…
Ahmed-Ali Nov 24, 2018
96d1f27
Merge branch 'ty0521-fss-feature/fix_java_gson_for_android' into develop
Ahmed-Ali Nov 24, 2018
1e806c9
Updating CHANGELOG.md
Ahmed-Ali Nov 24, 2018
a0a7c7e
Merge branch 'master' of git://github.com/BrychanOdlum/JSONExport int…
Ahmed-Ali Nov 24, 2018
101a4e9
Merge branch 'BrychanOdlum-master' into develop
Ahmed-Ali Nov 24, 2018
87f71cb
Updating CHANGELOG.md
Ahmed-Ali Nov 24, 2018
a507ecf
Fixing the project file
Ahmed-Ali Nov 24, 2018
db500f5
Updating CHANGELOG.md
Ahmed-Ali Nov 24, 2018
47a897e
Adding Outlaw JSON file to the project as the merge conflicts caused …
Ahmed-Ali Nov 24, 2018
a0ec494
nit: removing empty line
Ahmed-Ali Nov 24, 2018
50e3f93
Fixed an issue with trying to figure the selected language from an UI…
Ahmed-Ali Nov 24, 2018
fe313c0
fixed: update the color under Dark Mode
Sep 6, 2019
ec2051d
Merge pull request #136 from hzb/master
huabin Sep 8, 2019
8fe2606
add codable with default
Jul 2, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Adding Outlaw JSON file to the project as the merge conflicts caused …
…this to not to merge correctly
  • Loading branch information
Ahmed-Ali committed Nov 24, 2018
commit 47a897ea413e5212d01c634e4ffa66399dd7c032
8 changes: 8 additions & 0 deletions JSONExport.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
@@ -30,6 +30,8 @@
E2197C5D1A0EAEB900549D03 /* StringExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2197C5C1A0EAEB900549D03 /* StringExtension.swift */; };
E22BA2C51A162B54005CE143 /* FileContentBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = E22BA2C41A162B54005CE143 /* FileContentBuilder.swift */; };
E230BA2C1A113F8C00AE2054 /* FilePreviewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = E230BA2B1A113F8C00AE2054 /* FilePreviewCell.swift */; };
E24E443221AA12B800435FE7 /* Swift-Outlaw.json in Resources */ = {isa = PBXBuildFile; fileRef = E24E443021AA12B800435FE7 /* Swift-Outlaw.json */; };
E24E443321AA12B800435FE7 /* Swift3-Mappable.json in Resources */ = {isa = PBXBuildFile; fileRef = E24E443121AA12B800435FE7 /* Swift3-Mappable.json */; };
E278F9C61A2149AC00306EFC /* HeaderFileData.swift in Sources */ = {isa = PBXBuildFile; fileRef = E278F9C51A2149AC00306EFC /* HeaderFileData.swift */; };
E278F9CA1A2152D800306EFC /* HeaderFileRepresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = E278F9C91A2152D800306EFC /* HeaderFileRepresenter.swift */; };
E28631521A158CFA0041B178 /* Constructor.swift in Sources */ = {isa = PBXBuildFile; fileRef = E286314E1A158CFA0041B178 /* Constructor.swift */; };
@@ -72,6 +74,8 @@
E2197C5C1A0EAEB900549D03 /* StringExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StringExtension.swift; sourceTree = "<group>"; };
E22BA2C41A162B54005CE143 /* FileContentBuilder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FileContentBuilder.swift; sourceTree = "<group>"; };
E230BA2B1A113F8C00AE2054 /* FilePreviewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FilePreviewCell.swift; sourceTree = "<group>"; };
E24E443021AA12B800435FE7 /* Swift-Outlaw.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = "Swift-Outlaw.json"; path = "Supported Languages/Swift-Outlaw.json"; sourceTree = "<group>"; };
E24E443121AA12B800435FE7 /* Swift3-Mappable.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = "Swift3-Mappable.json"; path = "Supported Languages/Swift3-Mappable.json"; sourceTree = "<group>"; };
E278F9C51A2149AC00306EFC /* HeaderFileData.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HeaderFileData.swift; sourceTree = "<group>"; };
E278F9C91A2152D800306EFC /* HeaderFileRepresenter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HeaderFileRepresenter.swift; sourceTree = "<group>"; };
E286314E1A158CFA0041B178 /* Constructor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Constructor.swift; sourceTree = "<group>"; };
@@ -153,6 +157,8 @@
E2F07E8A1A0B3192004A1DAA /* Supported Languages */ = {
isa = PBXGroup;
children = (
E24E443021AA12B800435FE7 /* Swift-Outlaw.json */,
E24E443121AA12B800435FE7 /* Swift3-Mappable.json */,
166AF5CD1CEF6C3600516EDD /* Swift-Struct-Gloss.json */,
60FB8FFA1B9B3F6400290979 /* ObjectiveC-Realm.json */,
A329A7EC1D5DA1ED00FB59E8 /* Java-Android Gson.json */,
@@ -294,6 +300,7 @@
60FB8FF31B9B361600290979 /* ObjectiveC-iOS.json in Resources */,
60FB8FFC1B9B3F6400290979 /* ObjectiveC-Realm.json in Resources */,
60FB8FF11B9B361600290979 /* Java-Android.json in Resources */,
E24E443321AA12B800435FE7 /* Swift3-Mappable.json in Resources */,
60FB8FF81B9B361600290979 /* Swift-Struct.json in Resources */,
E2FA87BF1A059AC100648EB6 /* Images.xcassets in Resources */,
98978FC11D5B6B19000C1846 /* Swift-Struct-Unbox.json in Resources */,
@@ -303,6 +310,7 @@
60FB8FF91B9B361600290979 /* SwiftyJSON-Class.json in Resources */,
60FB8FF21B9B361600290979 /* ObjectiveC-CoreData-iOS.json in Resources */,
E2FA87C21A059AC100648EB6 /* Main.storyboard in Resources */,
E24E443221AA12B800435FE7 /* Swift-Outlaw.json in Resources */,
166AF5CE1CEF6C3600516EDD /* Swift-Struct-Gloss.json in Resources */,
60FB8FF41B9B361600290979 /* ObjectiveC-Mac.json in Resources */,
);
138 changes: 138 additions & 0 deletions JSONExport/Supported Languages/Swift-Outlaw.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
{
"modelStart": "{\n",
"importForEachCustomType": "",
"reservedKeywords": [
"abstract",
"assert",
"boolean",
"break",
"byte",
"case",
"catch",
"char",
"class",
"const",
"continue",
"default",
"do",
"double",
"else",
"enum",
"extends",
"false",
"final",
"finally",
"float",
"for",
"goto",
"if",
"implements",
"import",
"instanceof",
"int",
"interface",
"long",
"native",
"new",
"null",
"package",
"private",
"protected",
"public",
"return",
"short",
"static",
"strictfp",
"super",
"switch",
"synchronized",
"this",
"throw",
"throws",
"transient",
"true",
"try",
"void",
"volatile",
"while",
"class",
"description"
],
"booleanGetter": "",
"briefDescription": "Defines how your JSON objects can be mapped to Swift classes using the built-in NSJSONSerialization class",
"utilityMethods": [
{
"forEachProperty": "\t\tif <!VarName!> != nil{\n\t\t\tdictionary[\"<!JsonKeyName!>\"] = <!VarName!>\n\t\t}\n",
"bodyEnd": "\t}\n",
"signature": "\tfunc serialized() -> [String:Any]",
"forEachCustomTypeProperty": "\t\tif <!VarName!> != nil{\n\t\t\tdictionary[\"<!JsonKeyName!>\"] = <!VarName!>!.serialized()\n\t\t}\n",
"forEachArrayOfCustomTypeProperty": "\t\tif <!VarName!> != nil{\n\t\t\tvar dictionaryElements = [[String:Any]]()\n\t\t\tfor <!VarName!>Element in <!VarName!>! {\n\t\t\t\tdictionaryElements.append(<!VarName!>Element.serialized())\n\t\t\t}\n\t\t\tdictionary[\"<!JsonKeyName!>\"] = dictionaryElements\n\t\t}\n",
"returnStatement": "\t\treturn dictionary\n",
"body": "\t\tvar dictionary = [String:Any]()\n",
"comment": "\t/**\n\t * Returns all the available property values in the form of [String:Any] object where the key is the approperiate json key and the value is the value of the corresponding property\n\t */\n",
"bodyStart": "\n\t{\n"
},
{
"forEachProperty": " <!VarName!> = aDecoder.decodeObject(forKey: \"<!JsonKeyName!>\") as? <!VarType!>\n",
"bodyEnd": "\n\t}\n",
"signature": " @objc required init(coder aDecoder: NSCoder)",
"forEachCustomTypeProperty": " <!VarName!> = aDecoder.decodeObject(forKey: \"<!JsonKeyName!>\") as? <!VarType!>\n",
"forEachArrayOfCustomTypeProperty": " <!VarName!> = aDecoder.decodeObject(forKey :\"<!JsonKeyName!>\") as? <!VarType!>\n",
"returnStatement": "",
"body": "",
"comment": "\n /**\n * NSCoding required initializer.\n * Fills the data from the passed decoder\n */\n",
"bodyStart": "\n\t{\n"
},
{
"forEachProperty": "\t\tif <!VarName!> != nil{\n\t\t\taCoder.encode(<!VarName!>, forKey: \"<!JsonKeyName!>\")\n\t\t}\n",
"bodyEnd": "\n\t}\n",
"signature": " @objc func encode(with aCoder: NSCoder)",
"forEachCustomTypeProperty": "\t\tif <!VarName!> != nil{\n\t\t\taCoder.encode(<!VarName!>, forKey: \"<!JsonKeyName!>\")\n\t\t}\n",
"forEachArrayOfCustomTypeProperty": "\t\tif <!VarName!> != nil{\n\t\t\taCoder.encode(<!VarName!>, forKey: \"<!JsonKeyName!>\")\n\t\t}\n",
"returnStatement": "",
"body": "",
"comment": "\n /**\n * NSCoding required method.\n * Encodes mode properties into the decoder\n */\n",
"bodyStart": "\n\t{\n"
}
],
"dataTypes": {
"stringType": "String",
"boolType": "Bool",
"floatType": "Float",
"doubleType": "Double",
"characterType": "Character",
"longType": "Double",
"intType": "Int"
},
"wordsToRemoveToGetArrayElementsType": [
"[",
"]"
],
"defaultParentWithUtilityMethods": "NSObject, DataObject",
"constructors": [
{
"fetchBasicTypeWithSpecialNeedsPropertyFromMap": "",
"fetchCustomTypePropertyFromMap": "\t\tif let <!VarName!>Data = object.optionalAny(for: \"<!JsonKeyName!>\") as? [String:Any]{\n\t\t\t<!VarName!> = try <!VarType!>(object: <!VarName!>Data)\n\t\t}\n",
"bodyEnd": "\t}\n",
"fetchBasicTypePropertyFromMap": "\t\t<!VarName!> = object.value(for: \"<!JsonKeyName!>\")\n",
"signature": "\trequired init(object: Extractable) throws",
"fetchArrayOfCustomTypePropertyFromMap": "\t\t<!VarName!> = <!VarType!>()\n\t\tif let <!VarName!>Array = object.optionalAny(for: \"<!JsonKeyName!>\") as? [[String:Any]]{\n\t\t\tfor dic in <!VarName!>Array{\n\t\t\t\tlet value = try <!ElementType!>(object: dic)\n\t\t\t\t<!VarName!>!.append(value)\n\t\t\t}\n\t\t}\n",
"comment": "\t/**\n\t * Instantiate the instance using the passed dictionary values to set the properties values\n\t */\n",
"bodyStart": "{\n"
}
],
"modelDefinition": "\nclass <!ModelName!>",
"genericType": "AnyObject",
"getter": "",
"setter": "",
"displayLangName": "Swift - Outlaw",
"fileExtension": "swift",
"basicTypesWithSpecialFetchingNeeds": [],
"arrayType": "[<!ElementType!>]",
"modelDefinitionWithParent": "\n\nclass <!ModelName!> : <!ParentClass!>",
"instanceVarDefinition": "\tvar <!VarName!> : <!VarType!>?\n",
"supportsFirstLineStatement": "false",
"modelEnd": "\n}",
"staticImports": "import Foundation\nimport Outlaw",
"langName": "Swift"
}
15 changes: 10 additions & 5 deletions JSONExport/ViewController.swift
Original file line number Diff line number Diff line change
@@ -76,8 +76,10 @@ class ViewController: NSViewController, NSUserNotificationCenterDelegate, NSTabl
var selectedLang : LangModel!

//Returns the title of the selected language in the languagesPopup
//Call only from main thread
var selectedLanguageName : String
{
assert(Thread.isMainThread);
return languagesPopup.titleOfSelectedItem!
}

@@ -242,7 +244,10 @@ class ViewController: NSViewController, NSUserNotificationCenterDelegate, NSTabl
{
updateUIFieldsForSelectedLanguage()
generateClasses()
UserDefaults.standard.set(selectedLanguageName, forKey: "selectedLanguage")
DispatchQueue.main.async {
UserDefaults.standard.set(self.selectedLanguageName, forKey: "selectedLanguage")
}

}


@@ -261,8 +266,7 @@ class ViewController: NSViewController, NSUserNotificationCenterDelegate, NSTabl
//MARK: - Language selection handling
func loadSelectedLanguageModel()
{
selectedLang = langs[selectedLanguageName]

selectedLang = langs[self.selectedLanguageName]
}


@@ -411,9 +415,10 @@ class ViewController: NSViewController, NSUserNotificationCenterDelegate, NSTabl
}else{
json = unionDictionaryFromArrayElements(jsonData as! NSArray)
}
self.loadSelectedLanguageModel()
self.files.removeAll(keepingCapacity: false)

runOnUiThread{
self.loadSelectedLanguageModel()
self.files.removeAll(keepingCapacity: false)
let fileGenerator = self.prepareAndGetFilesBuilder()
fileGenerator.addFileWithName(&rootClassName, jsonObject: json, files: &self.files)
fileGenerator.fixReferenceMismatches(inFiles: self.files)