@@ -45,52 +45,36 @@ public struct ModelType {
45
45
public class ModelGenerator {
46
46
47
47
//MARK: Variables
48
- var authorName : String ?
49
- var companyName : String ?
50
- var prefix : String ?
51
- var baseContent : JSON
52
- var type : String
53
48
var filePath : String
54
49
var baseClassName : String
50
+ var baseContent : JSON
55
51
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 ?
63
61
64
62
65
63
//MARK: Public Methods
66
64
/**
67
65
Initalize the model generator with various settings.
68
66
69
67
- parameter baseContent: Base JSON that has to be converted into model.
70
- - parameter prefix: Prefix for the class.
71
68
- 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.
75
69
- parameter filePath: Filepath where the generated model has to be saved.
76
- - parameter includeSwiftyJSON: Boolean indicating if the header should have SwiftyJSON
77
70
78
71
- returns: A ModelGenerator instance.
79
72
*/
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 ) {
82
74
self . baseContent = baseContent
83
- self . prefix = prefix
84
- self . authorName = authorName != nil ? authorName : NSFullUserName ( )
85
- self . companyName = companyName
86
- self . type = type
87
75
self . filePath = filePath
88
76
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 ( )
94
78
}
95
79
96
80
/**
@@ -209,11 +193,11 @@ public class ModelGenerator {
209
193
// Replace all the generated properties in the appropriated placeholders in the template.
210
194
content = content. stringByReplacingOccurrencesOfString ( " {OBJECT_NAME} " , withString: className)
211
195
content = content. stringByReplacingOccurrencesOfString ( " {DATE} " , withString: todayDateString ( ) )
212
- content = content. stringByReplacingOccurrencesOfString ( " {OBJECT_KIND} " , withString: type)
196
+ content = content. stringByReplacingOccurrencesOfString ( " {OBJECT_KIND} " , withString: type! )
213
197
content = content. stringByReplacingOccurrencesOfString ( " {STRING_CONSTANT_BLOCK} " , withString: stringConstants)
214
198
content = content. stringByReplacingOccurrencesOfString ( " {PROPERTIES} " , withString: declarations)
215
199
216
- if self . supportNSCoding {
200
+ if self . supportNSCoding! {
217
201
if let nscodingBase = try ? String ( contentsOfFile: NSBundle . mainBundle ( ) . pathForResource ( " NSCodingTemplate " , ofType: " txt " ) !) {
218
202
content = content. stringByReplacingOccurrencesOfString ( " {NSCODING_PROTOCOL_SUPPORT} " , withString: " , NSCoding " )
219
203
content = content. stringByReplacingOccurrencesOfString ( " {NSCODING_SUPPORT} " , withString: nscodingBase)
@@ -231,13 +215,13 @@ public class ModelGenerator {
231
215
content = content. stringByReplacingOccurrencesOfString ( " {NSCODING_SUPPORT} " , withString: " " )
232
216
}
233
217
234
- if self . supportSwiftyJSON {
218
+ if self . supportSwiftyJSON! {
235
219
if let swiftyBase = try ? String ( contentsOfFile: NSBundle . mainBundle ( ) . pathForResource ( " SwiftyJSONTemplate " , ofType: " txt " ) !) {
236
220
content = content. stringByReplacingOccurrencesOfString ( " {SWIFTY_JSON_SUPPORT} " , withString: swiftyBase)
237
221
238
222
content = content. stringByReplacingOccurrencesOfString ( " {INITALIZER} " , withString: initalizers)
239
223
240
- if includeSwiftyJSON {
224
+ if includeSwiftyJSON! {
241
225
content = content. stringByReplacingOccurrencesOfString ( " {INCLUDE_SWIFTY} " , withString: " \n import SwiftyJSON " )
242
226
} else {
243
227
content = content. stringByReplacingOccurrencesOfString ( " {INCLUDE_SWIFTY} " , withString: " " )
@@ -253,15 +237,15 @@ public class ModelGenerator {
253
237
content = content. stringByReplacingOccurrencesOfString ( " {INCLUDE_SWIFTY} " , withString: " " )
254
238
}
255
239
256
- if self . supportObjectMapper {
240
+ if self . supportObjectMapper! {
257
241
if let objectMapperBase = try ? String ( contentsOfFile: NSBundle . mainBundle ( ) . pathForResource ( " ObjectMapperTemplate " , ofType: " txt " ) !) {
258
242
content = content. stringByReplacingOccurrencesOfString ( " {OBJECT_MAPPER_SUPPORT} " , withString: objectMapperBase)
259
243
260
244
content = content. stringByReplacingOccurrencesOfString ( " {OBJECT_MAPPER_INITIALIZER} " , withString: objectMapperMappings)
261
245
262
246
objectBaseClass = " Mappable "
263
247
264
- if includeObjectMapper {
248
+ if includeObjectMapper! {
265
249
content = content. stringByReplacingOccurrencesOfString ( " {INCLUDE_OBJECT_MAPPER} " , withString: " \n import ObjectMapper " )
266
250
} else {
267
251
content = content. stringByReplacingOccurrencesOfString ( " {INCLUDE_OBJECT_MAPPER} " , withString: " " )
0 commit comments