Last active
August 29, 2015 14:25
-
-
Save alanf/99d210113a3cdb1e4e3c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Magic! Just specify the type and the function on the right hand side will magically get you the correct view from the xib. | |
let noteView: AlterationReceiptNoteView = ViewUtil.viewFromNib(.JPAlterations) | |
public enum XIBFileName : String { | |
case Receipt = "ReceiptViewController" | |
case USAlterations = "AlterationReceiptUSView" | |
case JPAlterations = "AlterationReceiptsJapanView" | |
} | |
public class func viewFromNib<T>(nibName: XIBFileName) -> T { | |
let views = UINib(nibName: nibName.rawValue, bundle: nil).instantiateWithOwner(nil, options: nil) | |
for view in views { | |
if let desiredView = view as? T { | |
return desiredView | |
} | |
} | |
fatalError("Should have found a matching view for this type") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment