@@ -11,56 +11,56 @@ import Foundation
1111
1212/// MARK: Swift types
1313
14- struct Type : Printable {
15- static let _Void = Type ( className : " Void " )
16- static let _AnyObject = Type ( className : " AnyObject " )
17- static let _String = Type ( className : " String " )
18- static let _UINib = Type ( className : " UINib " )
19- static let _UIImage = Type ( className : " UIImage " )
20- static let _UIStoryboard = Type ( className : " UIStoryboard " )
21- static let _UIViewController = Type ( className : " UIViewController " )
22-
23- let moduleName : String ?
24- let className : String
14+ struct Type : Printable , Equatable {
15+ static let _Void = Type ( name : " Void " )
16+ static let _AnyObject = Type ( name : " AnyObject " )
17+ static let _String = Type ( name : " String " )
18+ static let _UINib = Type ( name : " UINib " )
19+ static let _UIImage = Type ( name : " UIImage " )
20+ static let _UIStoryboard = Type ( name : " UIStoryboard " )
21+ static let _UIViewController = Type ( name : " UIViewController " )
22+
23+ let module : String ?
24+ let name : String
2525 let optional : Bool
2626
2727 var fullyQualifiedName : String {
2828 let optionalString = optional ? " ? " : " "
2929
30- if let moduleName = moduleName {
31- return " \( moduleName ) . \( className ) \( optionalString) "
30+ if let module = module {
31+ return " \( module ) . \( ( name ) ) \( optionalString) "
3232 }
3333
34- return " \( className ) \( optionalString) "
34+ return " \( name ) \( optionalString) "
3535 }
3636
3737 var description : String {
3838 return fullyQualifiedName
3939 }
4040
41- init ( className : String , optional: Bool = false ) {
42- self . moduleName = nil
43- self . className = className
41+ init ( name : String , optional: Bool = false ) {
42+ self . module = nil
43+ self . name = name
4444 self . optional = optional
4545 }
4646
47- init ( moduleName : String ? , className : String , optional: Bool = false ) {
48- self . moduleName = moduleName
49- self . className = className
47+ init ( module : String ? , name : String , optional: Bool = false ) {
48+ self . module = module
49+ self . name = name
5050 self . optional = optional
5151 }
5252
5353 func asOptional( ) -> Type {
54- return Type ( moduleName : self . moduleName , className : className , optional: true )
54+ return Type ( module : module , name : name , optional: true )
5555 }
5656
5757 func asNonOptional( ) -> Type {
58- return Type ( moduleName : moduleName , className : className , optional: false )
58+ return Type ( module : module , name : name , optional: false )
5959 }
60+ }
6061
61- func isVoid( ) -> Bool {
62- return ( moduleName == Type . _Void. moduleName && className == Type . _Void. className && optional == Type . _Void. optional)
63- }
62+ func == ( lhs: Type , rhs: Type ) -> Bool {
63+ return ( lhs. module == rhs. module && lhs. name == rhs. name && lhs. optional == rhs. optional)
6464}
6565
6666struct Var : Printable {
@@ -83,7 +83,7 @@ struct Function: Printable {
8383 var description : String {
8484 let swiftName = sanitizedSwiftName ( name, lowercaseFirstCharacter: true )
8585 let parameterString = join ( " , " , parameters)
86- let returnString = returnType . isVoid ( ) ? " " : " -> \( returnType) "
86+ let returnString = Type . _Void == returnType ? " " : " -> \( returnType) "
8787 return " static func \( swiftName) ( \( parameterString) ) \( returnString) { \n \( indent ( body) ) \n } "
8888 }
8989
@@ -104,6 +104,7 @@ struct Function: Printable {
104104
105105 init ( name: String , type: Type ) {
106106 self . name = name
107+ self . localName = nil
107108 self . type = type
108109 }
109110
@@ -155,18 +156,23 @@ struct AssetFolder {
155156 init ( url: NSURL , fileManager: NSFileManager ) {
156157 name = url. filename!
157158
158- let contents = fileManager. contentsOfDirectoryAtURL ( url, includingPropertiesForKeys: nil , options: NSDirectoryEnumerationOptions . SkipsHiddenFiles, error: nil ) as [ NSURL ]
159+ let contents = fileManager. contentsOfDirectoryAtURL ( url, includingPropertiesForKeys: nil , options: NSDirectoryEnumerationOptions . SkipsHiddenFiles, error: nil ) as! [ NSURL ]
159160 imageAssets = contents. map { $0. filename! }
160161 }
161162}
162163
163164struct Storyboard : ReuseIdentifierContainer {
164165 let name : String
165166 let segues : [ String ]
167+ private let initialViewControllerIdentifier : String ?
166168 let viewControllers : [ ViewController ]
167169 let usedImageIdentifiers : [ String ]
168170 let reuseIdentifiers : [ String ]
169171
172+ var initialViewController : ViewController ? {
173+ return viewControllers. filter { $0. id == self . initialViewControllerIdentifier } . first
174+ }
175+
170176 init ( url: NSURL ) {
171177 name = url. filename!
172178
@@ -177,13 +183,15 @@ struct Storyboard: ReuseIdentifierContainer {
177183 parser. parse ( )
178184
179185 segues = parserDelegate. segues
186+ initialViewControllerIdentifier = parserDelegate. initialViewControllerIdentifier
180187 viewControllers = parserDelegate. viewControllers
181188 usedImageIdentifiers = parserDelegate. usedImageIdentifiers
182189 reuseIdentifiers = parserDelegate. reuseIdentifiers
183190 }
184191
185192 struct ViewController {
186- let storyboardIdentifier : String
193+ let id : String
194+ let storyboardIdentifier : String ?
187195 let type : Type
188196 }
189197}
@@ -210,13 +218,19 @@ struct Nib: ReuseIdentifierContainer {
210218/// MARK: Parsers
211219
212220class StoryboardParserDelegate : NSObject , NSXMLParserDelegate {
221+ var initialViewControllerIdentifier : String ?
213222 var segues : [ String ] = [ ]
214223 var viewControllers : [ Storyboard . ViewController ] = [ ]
215224 var usedImageIdentifiers : [ String ] = [ ]
216225 var reuseIdentifiers : [ String ] = [ ]
217226
218- func parser( parser: NSXMLParser ! , didStartElement elementName: String ! , namespaceURI: String ! , qualifiedName qName: String ! , attributes attributeDict: [ NSObject : AnyObject ] ! ) {
227+ func parser( parser: NSXMLParser , didStartElement elementName: String , namespaceURI: String ? , qualifiedName qName: String ? , attributes attributeDict: [ NSObject : AnyObject ] ) {
219228 switch elementName {
229+ case " document " :
230+ if let initialViewController = attributeDict [ " initialViewController " ] as? String {
231+ initialViewControllerIdentifier = initialViewController
232+ }
233+
220234 case " segue " :
221235 if let segueIdentifier = attributeDict [ " identifier " ] as? String {
222236 segues. append ( segueIdentifier)
@@ -240,16 +254,19 @@ class StoryboardParserDelegate: NSObject, NSXMLParserDelegate {
240254
241255 func viewControllerFromAttributes( attributeDict: [ NSObject : AnyObject ] , elementName: String ) -> Storyboard . ViewController ? {
242256 if attributeDict [ " sceneMemberID " ] as? String == " viewController " {
243- if let storyboardIdentifier = attributeDict [ " storyboardIdentifier " ] as? String {
244- let customModule = attributeDict [ " customModule " ] as? String
245- let customClass = attributeDict [ " customClass " ] as? String
246- let customType = customClass. map { Type ( moduleName: customModule, className: $0, optional: false ) }
257+ if let id = attributeDict [ " id " ] as? String {
258+ let storyboardIdentifier = attributeDict [ " storyboardIdentifier " ] as? String
247259
248- let type = customType ?? ElementNameToTypeMapping [ elementName] ?? Type . _UIViewController
249- return Storyboard . ViewController ( storyboardIdentifier: storyboardIdentifier, type: type)
250- }
260+ let customModule = attributeDict [ " customModule " ] as? String
261+ let customClass = attributeDict [ " customClass " ] as? String
262+ let customType = customClass. map { Type ( module: customModule, name: $0, optional: false ) }
263+
264+ let type = customType ?? ElementNameToTypeMapping [ elementName] ?? Type . _UIViewController
265+
266+ return Storyboard . ViewController ( id: id, storyboardIdentifier: storyboardIdentifier, type: type)
267+ }
251268 }
252-
269+
253270 return nil
254271 }
255272}
@@ -263,7 +280,7 @@ class NibParserDelegate: NSObject, NSXMLParserDelegate {
263280 var isObjectsTagOpened = false ;
264281 var levelSinceObjectsTagOpened = 0 ;
265282
266- func parser( parser: NSXMLParser ! , didStartElement elementName: String ! , namespaceURI: String ! , qualifiedName qName: String ! , attributes attributeDict: [ NSObject : AnyObject ] ! ) {
283+ func parser( parser: NSXMLParser , didStartElement elementName: String , namespaceURI: String ? , qualifiedName qName: String ? , attributes attributeDict: [ NSObject : AnyObject ] ) {
267284 switch elementName {
268285 case " objects " :
269286 isObjectsTagOpened = true ;
@@ -285,7 +302,7 @@ class NibParserDelegate: NSObject, NSXMLParserDelegate {
285302 }
286303 }
287304
288- func parser( parser: NSXMLParser ! , didEndElement elementName: String ! , namespaceURI: String ! , qualifiedName qName: String ! ) {
305+ func parser( parser: NSXMLParser , didEndElement elementName: String , namespaceURI: String ? , qualifiedName qName: String ? ) {
289306 switch elementName {
290307 case " objects " :
291308 isObjectsTagOpened = false ;
@@ -299,8 +316,8 @@ class NibParserDelegate: NSObject, NSXMLParserDelegate {
299316
300317 func viewWithAttributes( attributeDict: [ NSObject : AnyObject ] ) -> Type ? {
301318 let customModule = attributeDict [ " customModule " ] as? String
302- let customClass = attributeDict [ " customClass " ] as? String ?? " UIView "
319+ let customClass = ( attributeDict [ " customClass " ] as? String ) ?? " UIView "
303320
304- return Type ( moduleName : customModule, className : customClass)
321+ return Type ( module : customModule, name : customClass)
305322 }
306323}
0 commit comments