Skip to content

Commit

Permalink
Check element name when generating storyboard get viewController func…
Browse files Browse the repository at this point in the history
…tions

Fixes #11
  • Loading branch information
mac-cain13 committed Feb 1, 2015
1 parent 67b1681 commit b8bce81
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
11 changes: 7 additions & 4 deletions R.swift/types.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ struct Type: Printable {
static let _UINib = Type(className: "UINib")
static let _UIImage = Type(className: "UIImage")
static let _UIStoryboard = Type(className: "UIStoryboard")
static let _UIViewController = Type(className: "UIViewController")

let moduleName: String?
let className: String
Expand Down Expand Up @@ -218,19 +219,21 @@ class StoryboardParserDelegate: NSObject, NSXMLParserDelegate {
}

default:
if let viewController = viewControllerFromAttributes(attributeDict) {
if let viewController = viewControllerFromAttributes(attributeDict, elementName: elementName) {
viewControllers.append(viewController)
}
}
}

func viewControllerFromAttributes(attributeDict: [NSObject : AnyObject]) -> Storyboard.ViewController? {
func viewControllerFromAttributes(attributeDict: [NSObject : AnyObject], elementName: String) -> Storyboard.ViewController? {
if attributeDict["sceneMemberID"] as? String == "viewController" {
if let storyboardIdentifier = attributeDict["storyboardIdentifier"] as? String {
let customModule = attributeDict["customModule"] as? String
let customClass = attributeDict["customClass"] as? String ?? "UIViewController"
let customClass = attributeDict["customClass"] as? String
let customType = customClass.map { Type(moduleName: customModule, className: $0, optional: false) }

return Storyboard.ViewController(storyboardIdentifier: storyboardIdentifier, type: Type(moduleName: customModule, className: customClass, optional: false))
let type = customType ?? ElementNameToTypeMapping[elementName] ?? Type._UIViewController
return Storyboard.ViewController(storyboardIdentifier: storyboardIdentifier, type: type)
}
}

Expand Down
12 changes: 12 additions & 0 deletions R.swift/values.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,15 @@ let Ordinals = [
(number: 19, word: "nineteenth"),
(number: 20, word: "twentieth"),
]

let ElementNameToTypeMapping = [
"viewController": Type._UIViewController,
"glkViewController": Type(className: "GLKViewController"),
"tabBarController": Type(className: "UITabBarController"),
"pageViewController": Type(className: "UIPageViewController"),
"tableViewController": Type(className: "UITableViewController"),
"splitViewController": Type(className: "UISplitViewController"),
"navigationController": Type(className: "UINavigationController"),
"avPlayerViewController": Type(className: "AVPlayerViewController"),
"collectionViewController": Type(className: "UICollectionViewController"),
]

0 comments on commit b8bce81

Please sign in to comment.