Skip to content

Commit b740d19

Browse files
committed
#1 added support for arrays as the base object
1 parent c22643c commit b740d19

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

SwiftyJSONAccelerator/SJModelGenerator.swift

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,12 @@ public class ModelGenerator {
8383
// Notify user that the files are generated!
8484
let notification: NSUserNotification = NSUserNotification()
8585
notification.title = "SwiftyJSONAccelerator"
86-
notification.subtitle = "Completed - \(name).swift"
86+
if name.characters.count > 0 {
87+
notification.subtitle = "Completed - \(name).swift"
88+
} else {
89+
notification.subtitle = "No files were generated, cannot model arrays inside arrays."
90+
}
8791
NSUserNotificationCenter.defaultUserNotificationCenter().deliverNotification(notification)
88-
8992
}
9093

9194
//MARK: Internal methods
@@ -176,7 +179,6 @@ public class ModelGenerator {
176179

177180
}
178181

179-
180182
// Get an instance of the template.
181183
var content: String = templateContent()
182184

@@ -201,6 +203,16 @@ public class ModelGenerator {
201203
// Write everything to the file at the path.
202204
writeToFile(className, content: content, path: filePath)
203205

206+
} else if let object = parsedJSONObject.array {
207+
// Incase the first object was NOT a dictionary.
208+
// TODO: Instead of taking a single element consider merging all the elements and decide what to do as a while.
209+
let subClassType = checkType(object[0])
210+
211+
// If the type is an object then make it the base class and generate stuff.
212+
if subClassType == VariableType.kObjectType {
213+
self.generateModelForClass(object[0], className: className, isSubModule: false)
214+
}
215+
return ""
204216
}
205217

206218
return className

0 commit comments

Comments
 (0)