Skip to content

Commit 5e0390f

Browse files
author
Karthikeya Udupa KM
committed
Merge pull request #3 from insanoid/v0.0.3
Release 0.0.3
2 parents 9dec070 + 6272f3a commit 5e0390f

9 files changed

+208
-219
lines changed

README.md

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
# SwiftyJSONAccelerator
22

3-
**(Alpha v0.0.2)**
3+
**(Alpha v0.0.3)**
44

5-
[Download the .app (v0.0.2)](https://github.com/insanoid/SwiftyJSONAccelerator/releases/download/v0.0.2/SwiftyJSONAccelerator.zip)
5+
[Download the .app (v0.0.3)](https://github.com/insanoid/SwiftyJSONAccelerator/releases/download/v0.0.3/SwiftyJSONAccelertor.zip)
66

77
![Logo](https://raw.githubusercontent.com/insanoid/SwiftyJSONAccelerator/master/SwiftyJSONAccelerator/Assets.xcassets/AppIcon.appiconset/Icon_32x32%402x.png)
88

9-
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. it relies on [SwiftyJSON](https://github.com/SwiftyJSON/SwiftyJSON) and requires you to include it in your project.
9+
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.
10+
11+
The models that are generated depend on JSON object mapping libraries, currently the model can be generated to depend on any of the below mentioned mapping libraries:
12+
13+
- [SwiftyJSON](https://github.com/SwiftyJSON/SwiftyJSON)
14+
- [Hearst-DD/ObjectMapper](https://github.com/Hearst-DD/ObjectMapper) (Contributed by: [brendan09](https://github.com/brendan09))
1015

1116
Currently, the pattern is very similar to its Objective-C counterpart. It generates classes with following properties.
1217

13-
- Initalize with `JSON` (SwiftyJSON based)
18+
- Initalize with `JSON` (SwiftyJSON or ObjectMapper)
1419
- Initalize with `AnyObject`
15-
- `NSCoding` compliant (Can be Archived using `NSKeyedArchiver`)
16-
- Convert to `NSDictionary`
20+
- Optional `NSCoding` compliance.
21+
- Convert object to `NSDictionary`
1722

1823
![Preview](https://raw.githubusercontent.com/insanoid/SwiftyJSONAccelerator/master/preview.png)
1924

@@ -22,14 +27,14 @@ Currently, the pattern is very similar to its Objective-C counterpart. It genera
2227

2328
![Preview](https://raw.githubusercontent.com/insanoid/SwiftyJSONAccelerator/master/preview_ii.png)
2429

25-
*Files are generated individually making it more easy to use.*
30+
*Each class in the JSON is generated as a file.*
2631

2732
## TODO
2833

2934
- Handle blank array a bit better.
3035
- Better User Interface and icon.
3136
- Generate both `struct` and `class`.
32-
- Support for generation of models that do not need SwiftyJSON.
37+
- Support for further JSON object modelling libraries.
3338
- Add tests and integrate with Travis CI.
3439
- Create a Xcode plugin and a command line executor.
3540

SwiftyJSONAccelerator/Base Files/BaseTemplate.txt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,8 @@ public {OBJECT_KIND} {OBJECT_NAME}: {OBJECT_BASE_CLASS}{NSCODING_PROTOCOL_SUPPOR
1515
// MARK: Properties
1616
{PROPERTIES}
1717

18-
// MARK: Initalizers
1918
{SWIFTY_JSON_SUPPORT}
20-
2119
{OBJECT_MAPPER_SUPPORT}
22-
2320
/**
2421
Generates description of the object in the form of a NSDictionary.
2522
- returns: A Key value pair containing all valid values in the object.
@@ -28,10 +25,7 @@ public {OBJECT_KIND} {OBJECT_NAME}: {OBJECT_BASE_CLASS}{NSCODING_PROTOCOL_SUPPOR
2825

2926
var dictionary: [String : AnyObject ] = [ : ]
3027
{DESC}
31-
3228
return dictionary
3329
}
34-
3530
{NSCODING_SUPPORT}
36-
3731
}
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
// MARK: NSCoding Protocol
1+
2+
// MARK: NSCoding Protocol
23
required public init(coder aDecoder: NSCoder) {
34
{DECODERS}
45
}
56

67
public func encodeWithCoder(aCoder: NSCoder) {
78
{ENCODERS}
8-
}
9+
}

SwiftyJSONAccelerator/Base Files/ObjectMapperTemplate.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// MARK: ObjectMapper Initalizers
12
/**
23
Map a JSON object to this class using ObjectMapper
34
- parameter map: A mapping from ObjectMapper

SwiftyJSONAccelerator/Base Files/SwiftyJSONTemplate.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// MARK: SwiftyJSON Initalizers
12
/**
23
Initates the class based on the object
34
- parameter object: The object of either Dictionary or Array kind that was passed.
@@ -14,4 +15,4 @@
1415
*/
1516
public init(json: JSON) {
1617
{INITALIZER}
17-
}
18+
}

SwiftyJSONAccelerator/Base.lproj/Main.storyboard

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2-
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="9059" systemVersion="15A282b" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
2+
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="9059" systemVersion="15A284" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
33
<dependencies>
44
<deployment identifier="macosx"/>
55
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="9059"/>
@@ -699,10 +699,10 @@
699699
<animations/>
700700
<color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
701701
<color key="backgroundColor" white="0.0" alpha="1" colorSpace="calibratedWhite"/>
702-
<size key="minSize" width="700" height="461"/>
702+
<size key="minSize" width="715" height="461"/>
703703
<size key="maxSize" width="717" height="10000000"/>
704704
<color key="insertionPointColor" name="controlLightHighlightColor" catalog="System" colorSpace="catalog"/>
705-
<size key="minSize" width="700" height="461"/>
705+
<size key="minSize" width="715" height="461"/>
706706
<size key="maxSize" width="717" height="10000000"/>
707707
</textView>
708708
</subviews>
@@ -716,7 +716,7 @@
716716
<animations/>
717717
</scroller>
718718
<scroller key="verticalScroller" verticalHuggingPriority="750" horizontal="NO" id="9fh-RH-upi">
719-
<rect key="frame" x="701" y="1" width="15" height="461"/>
719+
<rect key="frame" x="700" y="1" width="16" height="461"/>
720720
<autoresizingMask key="autoresizingMask"/>
721721
<animations/>
722722
</scroller>

SwiftyJSONAccelerator/SJEditorViewController.swift

Lines changed: 41 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ import Cocoa
1212
class SJEditorViewController: NSViewController, NSTextViewDelegate {
1313

1414
// MARK: Outlet files.
15-
@IBOutlet var textView: SJTextView?
16-
@IBOutlet var messageLabel: NSTextField?
17-
@IBOutlet var errorImageView: NSImageView?
18-
@IBOutlet var baseClassTextField: NSTextField?
19-
@IBOutlet var prefixClassTextField: NSTextField?
20-
@IBOutlet var companyNameTextField: NSTextField?
21-
@IBOutlet var authorNameTextField: NSTextField?
22-
@IBOutlet var includeSwiftyCheckbox: NSButton?
15+
@IBOutlet var textView: SJTextView!
16+
@IBOutlet var messageLabel: NSTextField!
17+
@IBOutlet var errorImageView: NSImageView!
18+
@IBOutlet var baseClassTextField: NSTextField!
19+
@IBOutlet var prefixClassTextField: NSTextField!
20+
@IBOutlet var companyNameTextField: NSTextField!
21+
@IBOutlet var authorNameTextField: NSTextField!
22+
@IBOutlet var includeSwiftyCheckbox: NSButton!
2323
@IBOutlet var supportNSCodingCheckbox: NSButton!
2424
@IBOutlet var supportSwiftyJSONCheckbox: NSButton!
2525
@IBOutlet var supportObjectMapperCheckbox: NSButton!
@@ -49,12 +49,12 @@ class SJEditorViewController: NSViewController, NSTextViewDelegate {
4949
}
5050

5151
/**
52-
Validates and updates the textview.
52+
Validates and updates the textview.
5353

54-
- parameter pretty: If the JSON is to be pretty printed.
54+
- parameter pretty: If the JSON is to be pretty printed.
5555

56-
- returns: if the format was valid.
57-
*/
56+
- returns: if the format was valid.
57+
*/
5858
func validateAndFormat(pretty: Bool) -> Bool {
5959

6060
if textView?.string?.characters.count == 0 {
@@ -80,8 +80,8 @@ class SJEditorViewController: NSViewController, NSTextViewDelegate {
8080
}
8181

8282
/**
83-
Actual function that generates the model.
84-
*/
83+
Actual function that generates the model.
84+
*/
8585
func generateModel() {
8686

8787
// The base class field is blank, cannot proceed without it. Possibly can have a default value in the future.
@@ -106,13 +106,24 @@ class SJEditorViewController: NSViewController, NSTextViewDelegate {
106106

107107
let swiftyState = self.includeSwiftyCheckbox?.state == 1 ? true : false
108108
let supportSwiftyState = self.supportSwiftyJSONCheckbox?.state == 1 ? true : false
109-
109+
110110
let nscodingState = self.supportNSCodingCheckbox?.state == 1 ? true : false
111-
111+
112112
let objectMapperState = self.includeObjectMapperCheckbox?.state == 1 ? true : false
113113
let supportObjectMapperState = self.supportObjectMapperCheckbox?.state == 1 ? true : false
114114

115-
let generator: ModelGenerator = ModelGenerator.init(baseContent: JSON(object!), prefix: prefixClassTextField?.stringValue, baseClassName: (baseClassTextField?.stringValue)!, authorName: authorNameTextField?.stringValue, companyName: companyNameTextField?.stringValue, type: ModelType.kClassType, filePath: filePath!, supportSwiftyJSON: supportSwiftyState, includeSwiftyJSON: swiftyState, supportObjectMapper: supportObjectMapperState, includeObjectMapper: objectMapperState, supportNSCoding: nscodingState)
115+
let generator: ModelGenerator = ModelGenerator.init(baseContent: JSON(object!), baseClassName: baseClassTextField.stringValue, filePath: filePath!)
116+
117+
generator.prefix = prefixClassTextField.stringValue
118+
generator.authorName = authorNameTextField.stringValue
119+
generator.companyName = companyNameTextField.stringValue
120+
generator.type = ModelType.kClassType
121+
generator.supportSwiftyJSON = supportSwiftyState
122+
generator.includeSwiftyJSON = swiftyState
123+
generator.supportObjectMapper = supportObjectMapperState
124+
generator.includeObjectMapper = objectMapperState
125+
generator.supportNSCoding = nscodingState
126+
116127
generator.generate()
117128
} else {
118129
let alert:NSAlert = NSAlert()
@@ -122,7 +133,7 @@ class SJEditorViewController: NSViewController, NSTextViewDelegate {
122133
}
123134

124135
@IBAction func recalcEnabledBoxes(sender: AnyObject) {
125-
136+
126137
let supportSwiftyState = self.supportSwiftyJSONCheckbox?.state == 1 ? true : false
127138
let supportObjectMapperState = self.supportObjectMapperCheckbox?.state == 1 ? true : false
128139

@@ -132,15 +143,15 @@ class SJEditorViewController: NSViewController, NSTextViewDelegate {
132143
else {
133144
self.includeSwiftyCheckbox?.enabled = false
134145
}
135-
146+
136147
if supportObjectMapperState {
137148
self.includeObjectMapperCheckbox?.enabled = true
138149
}
139150
else {
140151
self.includeObjectMapperCheckbox?.enabled = false
141152
}
142153
}
143-
154+
144155
// MARK: Internal Methods
145156

146157
/**
@@ -177,11 +188,11 @@ class SJEditorViewController: NSViewController, NSTextViewDelegate {
177188
}
178189

179190
/**
180-
Handle Error message that is provided by the JSON helper and extract the message and showing them accordingly.
191+
Handle Error message that is provided by the JSON helper and extract the message and showing them accordingly.
181192

182-
- parameters:
183-
- error: NSError that was provided.
184-
*/
193+
- parameters:
194+
- error: NSError that was provided.
195+
*/
185196
func handleError(error: NSError?) {
186197
if let _ = error!.userInfo["debugDescription"] as? String? {
187198
let message: String = error!.userInfo["NSDebugDescription"]! as! String
@@ -214,19 +225,19 @@ class SJEditorViewController: NSViewController, NSTextViewDelegate {
214225
}
215226

216227
/**
217-
Show that the JSON is fine with proper icon.
218-
*/
228+
Show that the JSON is fine with proper icon.
229+
*/
219230
func correctJSONMessage() {
220231
errorImageView?.image = NSImage.init(named: "success")
221232
messageLabel?.stringValue = "Valid JSON!"
222233
}
223234

224235
/**
225-
Show the invalid JSON error with proper error and message.
236+
Show the invalid JSON error with proper error and message.
226237

227-
- parameters:
228-
- message: Error message that is to be shown.
229-
*/
238+
- parameters:
239+
- message: Error message that is to be shown.
240+
*/
230241
func invalidJSONError(message: String) {
231242
errorImageView?.image = NSImage.init(named: "failure")
232243
messageLabel?.stringValue = message

0 commit comments

Comments
 (0)