Skip to content

Commit 0ad74b4

Browse files
committed
#3 fixed initialisers
1 parent 2fb076d commit 0ad74b4

File tree

6 files changed

+44
-52
lines changed

6 files changed

+44
-52
lines changed

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/SJEditorViewController.swift

Lines changed: 20 additions & 9 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!
@@ -112,7 +112,18 @@ class SJEditorViewController: NSViewController, NSTextViewDelegate {
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()

SwiftyJSONAccelerator/SJModelGenerator.swift

Lines changed: 18 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -45,52 +45,36 @@ public struct ModelType {
4545
public class ModelGenerator {
4646

4747
//MARK: Variables
48-
var authorName: String?
49-
var companyName: String?
50-
var prefix: String?
51-
var baseContent: JSON
52-
var type: String
5348
var filePath: String
5449
var baseClassName: String
50+
var baseContent: JSON
5551

56-
var supportSwiftyJSON: Bool
57-
var includeSwiftyJSON: Bool
58-
59-
var supportObjectMapper: Bool
60-
var includeObjectMapper: Bool
61-
62-
var supportNSCoding: Bool
52+
var authorName: String?
53+
var companyName: String?
54+
var prefix: String?
55+
var type: String?
56+
var supportSwiftyJSON: Bool?
57+
var includeSwiftyJSON: Bool?
58+
var supportObjectMapper: Bool?
59+
var includeObjectMapper: Bool?
60+
var supportNSCoding: Bool?
6361

6462

6563
//MARK: Public Methods
6664
/**
6765
Initalize the model generator with various settings.
6866

6967
- parameter baseContent: Base JSON that has to be converted into model.
70-
- parameter prefix: Prefix for the class.
7168
- parameter baseClassName: Name of the base class.
72-
- parameter authorName: Name of the author, for use in the header documentation of the file.
73-
- parameter companyName: Name of the company, for use in the header documentation of the file.
74-
- parameter type: Type of the model that has to be generated, Struct or Class.
7569
- parameter filePath: Filepath where the generated model has to be saved.
76-
- parameter includeSwiftyJSON: Boolean indicating if the header should have SwiftyJSON
7770

7871
- returns: A ModelGenerator instance.
7972
*/
80-
init(baseContent: JSON, prefix: String?, baseClassName: String, authorName: String?, companyName: String?, type: String, filePath: String, supportSwiftyJSON: Bool, includeSwiftyJSON: Bool, supportObjectMapper: Bool, includeObjectMapper: Bool, supportNSCoding: Bool) {
81-
self.authorName = authorName
73+
init(baseContent: JSON, baseClassName: String, filePath: String) {
8274
self.baseContent = baseContent
83-
self.prefix = prefix
84-
self.authorName = authorName != nil ? authorName : NSFullUserName()
85-
self.companyName = companyName
86-
self.type = type
8775
self.filePath = filePath
8876
self.baseClassName = baseClassName
89-
self.supportSwiftyJSON = supportSwiftyJSON
90-
self.includeSwiftyJSON = includeSwiftyJSON
91-
self.supportNSCoding = supportNSCoding
92-
self.supportObjectMapper = supportObjectMapper
93-
self.includeObjectMapper = includeObjectMapper
77+
self.authorName = NSFullUserName()
9478
}
9579

9680
/**
@@ -209,11 +193,11 @@ public class ModelGenerator {
209193
// Replace all the generated properties in the appropriated placeholders in the template.
210194
content = content.stringByReplacingOccurrencesOfString("{OBJECT_NAME}", withString: className)
211195
content = content.stringByReplacingOccurrencesOfString("{DATE}", withString: todayDateString())
212-
content = content.stringByReplacingOccurrencesOfString("{OBJECT_KIND}", withString: type)
196+
content = content.stringByReplacingOccurrencesOfString("{OBJECT_KIND}", withString: type!)
213197
content = content.stringByReplacingOccurrencesOfString("{STRING_CONSTANT_BLOCK}", withString: stringConstants)
214198
content = content.stringByReplacingOccurrencesOfString("{PROPERTIES}", withString: declarations)
215199

216-
if self.supportNSCoding {
200+
if self.supportNSCoding! {
217201
if let nscodingBase = try? String(contentsOfFile: NSBundle.mainBundle().pathForResource("NSCodingTemplate", ofType: "txt")!) {
218202
content = content.stringByReplacingOccurrencesOfString("{NSCODING_PROTOCOL_SUPPORT}", withString: ", NSCoding")
219203
content = content.stringByReplacingOccurrencesOfString("{NSCODING_SUPPORT}", withString: nscodingBase)
@@ -231,13 +215,13 @@ public class ModelGenerator {
231215
content = content.stringByReplacingOccurrencesOfString("{NSCODING_SUPPORT}", withString: "")
232216
}
233217

234-
if self.supportSwiftyJSON {
218+
if self.supportSwiftyJSON! {
235219
if let swiftyBase = try? String(contentsOfFile: NSBundle.mainBundle().pathForResource("SwiftyJSONTemplate", ofType: "txt")!) {
236220
content = content.stringByReplacingOccurrencesOfString("{SWIFTY_JSON_SUPPORT}", withString: swiftyBase)
237221

238222
content = content.stringByReplacingOccurrencesOfString("{INITALIZER}", withString: initalizers)
239223

240-
if includeSwiftyJSON {
224+
if includeSwiftyJSON! {
241225
content = content.stringByReplacingOccurrencesOfString("{INCLUDE_SWIFTY}", withString: "\nimport SwiftyJSON")
242226
} else {
243227
content = content.stringByReplacingOccurrencesOfString("{INCLUDE_SWIFTY}", withString: "")
@@ -253,15 +237,15 @@ public class ModelGenerator {
253237
content = content.stringByReplacingOccurrencesOfString("{INCLUDE_SWIFTY}", withString: "")
254238
}
255239

256-
if self.supportObjectMapper {
240+
if self.supportObjectMapper! {
257241
if let objectMapperBase = try? String(contentsOfFile: NSBundle.mainBundle().pathForResource("ObjectMapperTemplate", ofType: "txt")!) {
258242
content = content.stringByReplacingOccurrencesOfString("{OBJECT_MAPPER_SUPPORT}", withString: objectMapperBase)
259243

260244
content = content.stringByReplacingOccurrencesOfString("{OBJECT_MAPPER_INITIALIZER}", withString: objectMapperMappings)
261245

262246
objectBaseClass = "Mappable"
263247

264-
if includeObjectMapper {
248+
if includeObjectMapper! {
265249
content = content.stringByReplacingOccurrencesOfString("{INCLUDE_OBJECT_MAPPER}", withString: "\nimport ObjectMapper")
266250
} else {
267251
content = content.stringByReplacingOccurrencesOfString("{INCLUDE_OBJECT_MAPPER}", withString: "")

0 commit comments

Comments
 (0)