Skip to content

Commit 682a8ea

Browse files
author
Karthikeya Udupa KM
authored
Merge pull request #50 from insanoid/releases/v1.3.0
Releases/v1.3.0
2 parents 94b2592 + 9ec48cc commit 682a8ea

File tree

13 files changed

+155
-141
lines changed

13 files changed

+155
-141
lines changed

README.md

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,22 @@
11
![Logo](https://raw.githubusercontent.com/insanoid/SwiftyJSONAccelerator/master/SwiftyJSONAccelerator/Support/Assets.xcassets/AppIcon.appiconset/Icon_32x32%402x.png)
22

3-
# SwiftyJSONAccelerator
3+
# SwiftyJSONAccelerator (Model file Generator For Swift 3)
44

55
[![Build
66
Status](https://travis-ci.org/insanoid/SwiftyJSONAccelerator.svg?branch=master)](https://travis-ci.org/insanoid/SwiftyJSONAccelerator) [![codecov](https://codecov.io/gh/insanoid/SwiftyJSONAccelerator/branch/master/graph/badge.svg)](https://codecov.io/gh/insanoid/SwiftyJSONAccelerator)
77

8-
**Version v1.2.0 Released!**
9-
10-
- Now supports [Marshal](https://github.com/utahiosmac/Marshal)! One of the fastest JSONSerialisation class out there! [(Read more)](https://github.com/bwhiteley/JSONShootout)
11-
- Set `class` as `final`.
12-
- `init` marked as `required` by default for `class`.
13-
14-
**Version v1.1.0 Released!**
15-
16-
- Now generates the correct option `struct` and `class` based on what was selected.
8+
**Version v1.3.0 Released!**
179

18-
**Version v1.0.0 Released!**
10+
- Serialisation keys moved into a struct for clarity.
11+
- Minor fixes for Marshal and ObjectMapper.
12+
- Generated comments now updated to the new Swift 3 Markup.
1913

20-
- Now generates **Swift 3** and the software itself is upgraded to Swift 3.
21-
- Unit tests and complete code coverage for file generation module.
22-
- Modular code to make adding support for other JSON mapping libraries simple.
23-
- Project upgraded with SwiftLint, Travis, CocoaPods etc.
14+
[Previous Release Notes](#previous-releases)
2415

2516
## Download/Installing
2617

2718
- **Option 1:** Download the repo, install pods and run the project!
28-
- **Option 2:** [Download the .app(v1.2.0)](https://github.com/insanoid/SwiftyJSONAccelerator/releases/download/v1.2.0/SwiftyJSONAccelerator.zip)
19+
- **Option 2:** [Download the .app(v1.3.0)](https://github.com/insanoid/SwiftyJSONAccelerator/releases/download/v1.3.0/SwiftyJSONAccelerator.zip)
2920

3021
A swift model generator like the Objective-C [JSONAccelerator](http://nerdery.com/json-accelerator). Formats and generates models for the given JSON and also breaks them into files making it easy to manage and share between several models.
3122

@@ -53,6 +44,25 @@ Currently, the pattern is very similar to its Objective-C counterpart. It genera
5344
- Do the necessary UI changes for the dropdown.
5445
- Add tests for your library.
5546

47+
## Previous Releases
48+
49+
**Version v1.2.0 Released!**
50+
51+
- Now supports [Marshal](https://github.com/utahiosmac/Marshal)! One of the fastest JSONSerialisation class out there! [(Read more)](https://github.com/bwhiteley/JSONShootout)
52+
- Set `class` as `final`.
53+
- `init` marked as `required` by default for `class`.
54+
55+
**Version v1.1.0 Released!**
56+
57+
- Now generates the correct option `struct` and `class` based on what was selected.
58+
59+
**Version v1.0.0 Released!**
60+
61+
- Now generates **Swift 3** and the software itself is upgraded to Swift 3.
62+
- Unit tests and complete code coverage for file generation module.
63+
- Modular code to make adding support for other JSON mapping libraries simple.
64+
- Project upgraded with SwiftLint, Travis, CocoaPods etc.
65+
5666
## Swift 2?
5767

5868
[Download (v0.0.6)](https://github.com/insanoid/SwiftyJSONAccelerator/releases/download/v0.0.6/SwiftyJSONAccelerator.zip), the older version of the project, please keep in mind it is **no longer supported**.

SwiftyJSONAccelerator/Generators/FileGenerator.swift

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ struct FileGenerator {
3333
static func generateFileContentWith(_ modelFile: ModelFile, configuration: ModelGenerationConfiguration) -> String {
3434

3535
var content = loadFileWith("BaseTemplate")
36+
let singleTab = " ", doubleTab = " "
3637
content = content.replacingOccurrences(of: "{OBJECT_NAME}", with: modelFile.fileName)
3738
content = content.replacingOccurrences(of: "{DATE}", with: todayDateString())
3839
content = content.replacingOccurrences(of: "{OBJECT_KIND}", with: modelFile.type.rawValue)
@@ -73,10 +74,11 @@ struct FileGenerator {
7374
content = content.replacingOccurrences(of: "{EXTENDED_OBJECT_COLON}", with: "")
7475
}
7576

76-
let stringConstants = modelFile.component.stringConstants.map({ " " + $0 }).joined(separator: "\n")
77-
let declarations = modelFile.component.declarations.map({ " " + $0 }).joined(separator: "\n")
78-
let initialisers = modelFile.component.initialisers.map({ " " + $0 }).joined(separator: "\n")
79-
let description = modelFile.component.description.map({ " " + $0 }).joined(separator: "\n")
77+
78+
let stringConstants = modelFile.component.stringConstants.map({doubleTab + $0 }).joined(separator: "\n")
79+
let declarations = modelFile.component.declarations.map({ singleTab + $0 }).joined(separator: "\n")
80+
let initialisers = modelFile.component.initialisers.map({doubleTab + $0 }).joined(separator: "\n")
81+
let description = modelFile.component.description.map({ doubleTab + $0 }).joined(separator: "\n")
8082

8183
content = content.replacingOccurrences(of: "{STRING_CONSTANT}", with: stringConstants)
8284
content = content.replacingOccurrences(of: "{DECLARATION}", with: declarations)
@@ -89,8 +91,8 @@ struct FileGenerator {
8991

9092
if configuration.supportNSCoding && configuration.constructType == .ClassType {
9193
content = content.replacingOccurrences(of: "{NSCODING_SUPPORT}", with: loadFileWith("NSCodingTemplate"))
92-
let encoders = modelFile.component.encoders.map({ " " + $0 }).joined(separator: "\n")
93-
let decoders = modelFile.component.decoders.map({ " " + $0 }).joined(separator: "\n")
94+
let encoders = modelFile.component.encoders.map({ doubleTab + $0 }).joined(separator: "\n")
95+
let decoders = modelFile.component.decoders.map({ doubleTab + $0 }).joined(separator: "\n")
9496
content = content.replacingOccurrences(of: "{DECODERS}", with: decoders)
9597
content = content.replacingOccurrences(of: "{ENCODERS}", with: encoders)
9698
} else {

SwiftyJSONAccelerator/Generators/ModelGenerator.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public struct ModelGenerator {
6666

6767
if let rootObject = object.dictionary {
6868
// A model file to store the current model.
69-
var currentModel = self.initaliseModelFileFor(configuration.modelMappingLibrary)
69+
var currentModel = self.initialiseModelFileFor(configuration.modelMappingLibrary)
7070
currentModel.setInfo(className, configuration)
7171

7272
for (key, value) in rootObject {
@@ -139,7 +139,7 @@ public struct ModelGenerator {
139139

140140
- returns: A new model file of the required type.
141141
*/
142-
func initaliseModelFileFor(_ modelMappingLibrary: JSONMappingLibrary) -> ModelFile {
142+
func initialiseModelFileFor(_ modelMappingLibrary: JSONMappingLibrary) -> ModelFile {
143143
switch modelMappingLibrary {
144144
case .ObjectMapper:
145145
return ObjectMapperModelFile()

SwiftyJSONAccelerator/Generators/NameGenerator.swift

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,8 @@ struct NameGenerator {
6868
*/
6969
static func replaceKeywords(_ currentName: String) -> String {
7070

71-
let keywordsWithReplacements = ["id": "internalIdentifier",
71+
let keywordsWithReplacements = [
7272
"description": "descriptionValue",
73-
"_id": "internalIdentifier",
7473
"class": "classProperty",
7574
"struct": "structProperty",
7675
"enum": "enumProperty",
@@ -91,8 +90,6 @@ struct NameGenerator {
9190
- returns: The name for the key for the variable in the given class.
9291
*/
9392
static func variableKey(_ className: String, _ variableName: String) -> String {
94-
var _variableName = variableName
95-
_variableName.uppercaseFirst()
96-
return "k\(className)\(_variableName)Key"
93+
return "SerializationKeys.\(variableName)"
9794
}
9895
}

SwiftyJSONAccelerator/Models-Components/DefaultModelFileComponent.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,9 @@ protocol DefaultModelFileComponent {
116116
extension DefaultModelFileComponent {
117117

118118
func genStringConstant(_ constantName: String, _ value: String) -> String {
119-
return "private let \(constantName): String = \"\(value)\""
119+
//The incoming string is in the format "SeralizationKey.ConstantName" we only need the second part.
120+
let component = constantName.components(separatedBy: ".")
121+
return "static let \(component.last!) = \"\(value)\""
120122
}
121123

122124
func genVariableDeclaration(_ name: String, _ type: String, _ isArray: Bool) -> String {
@@ -129,7 +131,7 @@ extension DefaultModelFileComponent {
129131

130132
func genPrimitiveVariableDeclaration(_ name: String, _ type: String) -> String {
131133
if type == VariableType.Bool.rawValue {
132-
return "public var \(name): \(type) = false"
134+
return "public var \(name): \(type)? = false"
133135
}
134136
return "public var \(name): \(type)?"
135137
}

SwiftyJSONAccelerator/Models-Components/ModelComponent.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ internal struct ModelComponent {
2727
var description: [String]
2828

2929
/**
30-
Initalise a blank model component structure.
30+
Initialise a blank model component structure.
3131
*/
3232
init() {
3333
declarations = []

SwiftyJSONAccelerator/Support/Info.plist

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@
1717
<key>CFBundlePackageType</key>
1818
<string>APPL</string>
1919
<key>CFBundleShortVersionString</key>
20-
<string>1.2.0</string>
20+
<string>1.3.0</string>
2121
<key>CFBundleSignature</key>
2222
<string>????</string>
2323
<key>CFBundleVersion</key>
24-
<string>8</string>
24+
<string>9</string>
25+
<key>LSApplicationCategoryType</key>
26+
<string>public.app-category.developer-tools</string>
2527
<key>LSMinimumSystemVersion</key>
2628
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
2729
<key>NSHumanReadableCopyright</key>

SwiftyJSONAccelerator/Templates/BaseTemplate.txt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,17 @@ import Foundation{INCLUDE_HEADER}
1010
public{IS_FINAL}{OBJECT_KIND} {OBJECT_NAME}{EXTENDED_OBJECT_COLON}{EXTEND_FROM} {
1111

1212
// MARK: Declaration for string constants to be used to decode and also serialize.
13+
private struct SerializationKeys {
1314
{STRING_CONSTANT}
15+
}
1416

1517
// MARK: Properties
1618
{DECLARATION}
1719

1820
{JSON_PARSER_LIBRARY_BODY}
19-
/**
20-
Generates description of the object in the form of a NSDictionary.
21-
- returns: A Key value pair containing all valid values in the object.
22-
*/
21+
/// Generates description of the object in the form of a NSDictionary.
22+
///
23+
/// - returns: A Key value pair containing all valid values in the object.
2324
public func dictionaryRepresentation() -> [String: Any] {
2425
var dictionary: [String: Any] = [:]
2526
{DESCRIPTION}
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
// MARK: Marshal Initializers
22

3-
/**
4-
Map a JSON object to this class using ObjectMapper
5-
- parameter map: A mapping from ObjectMapper
6-
*/
3+
/// Map a JSON object to this class using Marshal.
4+
///
5+
/// - parameter object: A mapping from ObjectMapper
76
public{REQUIRED}init(object: MarshaledObject) {
87
{INITIALIZER}
98
}
Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
// MARK: ObjectMapper Initializers
2-
/**
3-
Map a JSON object to this class using ObjectMapper
4-
- parameter map: A mapping from ObjectMapper
5-
*/
6-
public{REQUIRED}init?(_ map: Map){
2+
/// Map a JSON object to this class using ObjectMapper.
3+
///
4+
/// - parameter map: A mapping from ObjectMapper.
5+
public{REQUIRED}init?(map: Map){
76

87
}
98

10-
/**
11-
Map a JSON object to this class using ObjectMapper
12-
- parameter map: A mapping from ObjectMapper
13-
*/
9+
/// Map a JSON object to this class using ObjectMapper.
10+
///
11+
/// - parameter map: A mapping from ObjectMapper.
1412
public func mapping(map: Map) {
1513
{INITIALIZER}
1614
}
Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
// MARK: SwiftyJSON Initializers
2-
/**
3-
Initiates the instance based on the object
4-
- parameter object: The object of either Dictionary or Array kind that was passed.
5-
- returns: An initialized instance of the class.
6-
*/
2+
/// Initiates the instance based on the object.
3+
///
4+
/// - parameter object: The object of either Dictionary or Array kind that was passed.
5+
/// - returns: An initialized instance of the class.
76
public convenience init(object: Any) {
87
self.init(json: JSON(object))
98
}
109

11-
/**
12-
Initiates the instance based on the JSON that was passed.
13-
- parameter json: JSON object from SwiftyJSON.
14-
- returns: An initialized instance of the class.
15-
*/
10+
/// Initiates the instance based on the JSON that was passed.
11+
///
12+
/// - parameter json: JSON object from SwiftyJSON.
1613
public{REQUIRED}init(json: JSON) {
1714
{INITIALIZER}
1815
}

0 commit comments

Comments
 (0)