Skip to content
This repository has been archived by the owner on Sep 6, 2019. It is now read-only.

Multiple file input + Non-custom identifier-initializable view controllers #65

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 30 additions & 20 deletions natalie.swift
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,8 @@ enum OS: String, Printable {
switch self {
case iOS:
switch name {
case "viewController":
return "UIViewController"
case "navigationController":
return "UINavigationController"
case "tableViewController":
Expand All @@ -758,6 +760,8 @@ enum OS: String, Printable {
}
case OSX:
switch name {
case "viewController":
return "NSViewController"
case "pagecontroller":
return "NSPageController"
case "tabViewController":
Expand Down Expand Up @@ -893,20 +897,23 @@ class Storyboard: XMLObject {
if let initialViewControllerId = xml["document"].element?.attributes["initialViewController"],
xmlVC = searchById(initialViewControllerId)
{
let vc = ViewController(xml: xmlVC)
if let customClassName = vc.customClass {
return customClassName
}

if let name = vc.name, controllerType = os.controllerTypeForElementName(name) {
return controllerType
}
return self.classNameForViewController(ViewController(xml: xmlVC))
}
return nil
}


private func classNameForViewController(vc: ViewController) -> String? {
if let customClassName = vc.customClass {
return customClassName
} else if let name = vc.name, controllerType = os.controllerTypeForElementName(name) {
return controllerType
} else {
return nil
}
}

lazy var version: String? = self.xml["document"].element?.attributes["version"]
lazy var scenes: [Scene] = {
if let scenes = self.searchAll(self.xml, attributeKey: "sceneID"){
return scenes.map { Scene(xml: $0) }
Expand Down Expand Up @@ -936,10 +943,10 @@ class Storyboard: XMLObject {
println(" return self.storyboard.instantiate\(os.storyboardControllerSignatureType)WithIdentifier(identifier)\(os.storyboardControllerReturnTypeCast)")
println(" }")
for scene in self.scenes {
if let viewController = scene.viewController, customClass = viewController.customClass, storyboardIdentifier = viewController.storyboardIdentifier {
if let viewController = scene.viewController, className = self.classNameForViewController(viewController), storyboardIdentifier = viewController.storyboardIdentifier {
println()
println(" static func instantiate\(storyboardIdentifier.trimAllWhitespacesAndSpecialCharacters)() -> \(customClass)! {")
println(" return self.storyboard.instantiate\(os.storyboardControllerSignatureType)WithIdentifier(\"\(storyboardIdentifier)\") as! \(customClass)")
println(" static func instantiate\(storyboardIdentifier.trimAllWhitespacesAndSpecialCharacters)() -> \(className)! {")
println(" return self.storyboard.instantiate\(os.storyboardControllerSignatureType)WithIdentifier(\"\(storyboardIdentifier)\") as! \(className)")
println(" }")
}
}
Expand Down Expand Up @@ -1293,17 +1300,20 @@ func processStoryboards(storyboards: [StoryboardFile], os: OS) {
//MARK: MAIN()

if Process.arguments.count == 1 {
println("Invalid usage. Missing path to storyboard.")
println("Invalid usage. Missing path to storyboard(s).")
exit(0)
}

let argument = Process.arguments[1]
var storyboards:[String] = []
let storyboardSuffix = ".storyboard"
if argument.hasSuffix(storyboardSuffix) {
storyboards = [argument]
} else if let s = findStoryboards(argument, storyboardSuffix) {
storyboards = s
let storyboards = flatMap(Process.arguments[1..<Process.arguments.count]) { (argument: String) -> [String] in
if argument.hasSuffix(storyboardSuffix) {
return [argument]
} else if let s = findStoryboards(argument, storyboardSuffix) {
return s
} else {
println("Invalid argument: \(argument)")
exit(0)
}
}
let storyboardFiles: [StoryboardFile] = storyboards.map { StoryboardFile(filePath: $0) }

Expand Down