 
 }
 
-private func searchAll(root: XMLIndexer, attributeKey: String, attributeValue: String) -> [XMLIndexer]? {
-    var result = Array<XMLIndexer>()
-    for child in root.children {
-        if let element = child.element where element.attributes[attributeKey] == attributeValue {
-            return [child]
-        }
-        if let found = searchAll(child, attributeKey, attributeValue) {
-            result += found
-        }
-    }
-    return result.count > 0 ? result : nil
-}
-
-func findStoryboards(rootPath: String) -> [String]? {
-    var result = Array<String>()
-    let fm = NSFileManager.defaultManager()
-    var error:NSError?
-    if let paths = fm.subpathsAtPath(rootPath) as? [String]  {
-        let storyboardPaths = paths.filter({ return $0.hasSuffix(".storyboard")})
-        // result = storyboardPaths
-        for p in storyboardPaths {
-            result.append(rootPath.stringByAppendingPathComponent(p))
-        }
-    }
-    return result.count > 0 ? result : nil
-}
-
-func findInitialViewControllerClass(storyboardFile: String, os: OS) -> String? {
-    if let data = NSData(contentsOfFile: storyboardFile) {
-        let xml = SWXMLHash.parse(data)
-        if let initialViewControllerId = xml["document"].element?.attributes["initialViewController"] {
-            if let vc = searchAll(xml["document"], "id",initialViewControllerId)?.first {
+class StoryboardFile {
+    
+    let filePath: String
+    init(filePath: String){
+        self.filePath = filePath
+    }
+    
+    lazy var storyboardName: String = self.filePath.lastPathComponent.stringByDeletingPathExtension
+    
+    lazy var data: NSData? = NSData(contentsOfFile: self.filePath)
+    lazy var xml: XMLIndexer? = {
+        if let d = self.data {
+            return SWXMLHash.parse(d)
+        }
+        return nil
+        }()
+    
+    lazy var os:OS = self.initOS() ?? OS.iOS
+    private func initOS() -> OS? {
+        if let xml = self.xml, targetRuntime = xml["document"].element?.attributes["targetRuntime"] {
+            return OS.fromTargetRuntime(targetRuntime)
+        }
+        return nil
+    }
+    
+    lazy var initialViewControllerClass: String? = self.initOInitialViewControllerClass()
+    private func initOInitialViewControllerClass() -> String? {
+        if let xml = self.xml,
+            initialViewControllerId = xml["document"].element?.attributes["initialViewController"],
+            vc = searchAll(xml["document"], "id",initialViewControllerId)?.first {
                 if let customClassName = vc.element?.attributes["customClass"] {
                     return customClassName
                 }

                        println("            }")
                        println("        }")
                        println()
                        println("        var destination: UIViewController.Type? {")
                        println("            switch (self) {")
                        for segue in segues {
                            if let identifier = segue.element?.attributes["identifier"],

// Author: Marcin Krzyżanowski http://blog.krzyzanowskim.com
//

//MARK: SWXMLHash
//
//  SWXMLHash.swift
//
