Skip to content

Commit

Permalink
Reduce nesting in storyboard deserializer
Browse files Browse the repository at this point in the history
[#127426993]
  • Loading branch information
jwfriese committed Aug 1, 2016
1 parent 088fcf3 commit 3de7f04
Showing 1 changed file with 21 additions and 24 deletions.
45 changes: 21 additions & 24 deletions Fleet/CoreExtensions/Storyboard/StoryboardDeserializer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,30 @@ class StoryboardDeserializer {
}

var reference = StoryboardReferenceMap()
let storyboardInfoDictionary = NSDictionary(contentsOfFile: storyboardPath)
if let storyboardInfoDictionary = storyboardInfoDictionary {
if let nibNameDictionary = storyboardInfoDictionary["UIViewControllerIdentifiersToNibNames"] as? [String : String] {
reference.viewControllerIdentifiers = nibNameDictionary.map() { (key, value) in
return key
}
guard let storyboardInfoDictionary = NSDictionary(contentsOfFile: storyboardPath) else { return reference }
if let nibNameDictionary = storyboardInfoDictionary["UIViewControllerIdentifiersToNibNames"] as? [String : String] {
reference.viewControllerIdentifiers = nibNameDictionary.map() { (key, value) in
return key
}

let externalReferencesKey = "UIViewControllerIdentifiersToExternalStoryboardReferences"
let externalReferences = storyboardInfoDictionary[externalReferencesKey]
if let externalReferences = externalReferences as? [String : AnyObject] {
for identifier in externalReferences.keys {
var newRef = ExternalReferenceDefinition()
if let referenceDictionary = externalReferences[identifier] as? [String : String] {
newRef.connectedViewControllerIdentifier = identifier
if let externalStoryboardName = referenceDictionary["UIReferencedStoryboardName"] {
newRef.externalStoryboardName = externalStoryboardName
}

if let externalViewControllerIdentifier = referenceDictionary["UIReferencedControllerIdentifier"] {
newRef.externalViewControllerIdentifier = externalViewControllerIdentifier
}
}

reference.externalReferences.append(newRef)
}

let externalReferencesKey = "UIViewControllerIdentifiersToExternalStoryboardReferences"
guard let externalReferences = storyboardInfoDictionary[externalReferencesKey] as? [String : AnyObject] else { return reference }

for identifier in externalReferences.keys {
var newRef = ExternalReferenceDefinition()
if let referenceDictionary = externalReferences[identifier] as? [String : String] {
newRef.connectedViewControllerIdentifier = identifier
if let externalStoryboardName = referenceDictionary["UIReferencedStoryboardName"] {
newRef.externalStoryboardName = externalStoryboardName
}

if let externalViewControllerIdentifier = referenceDictionary["UIReferencedControllerIdentifier"] {
newRef.externalViewControllerIdentifier = externalViewControllerIdentifier
}
}

reference.externalReferences.append(newRef)
}

return reference
Expand Down

0 comments on commit 3de7f04

Please sign in to comment.