I have an Objective-C category used to customise
UIStoryboard's '+ (UIStoryboard *)storyboardWithName:(NSString *)name'.
It is used to determine which storyboard file to call when dealing with multiple devices. Now I need to change it to Swift.
It seems that I need to create a "Swift Extension", but am having issues getting it to work.
Here is what I have:
extension UIStoryboard {
convenience init(name: String, storyboardBundleOrNil: NSBundle?)
{
var storyboard: UIStoryboard?
var storyboardName: String?
// Don't adjust name if it's universal storyboard (Xcode 6, iOS 8)
storyboardName = name;
if (name.rangeOfString("_Universal") == nil)
{
if (UIDevice.currentDevice().userInterfaceIdiom == .Pad)
{
storyboardName = storyboardName!+"_iPad"
}
else
{
storyboardName = storyboardName!+"_iPhone"
}
}
// storyboard = UIStoryboard(name: storyboardName!, storyboardBundleOrNil: storyboardBundleOrNil!)
assert(storyboard != nil, "Storyboard %@ not found!")
//return storyboard!;
self.init(name: storyboardName!, storyboardBundleOrNil: storyboardBundleOrNil!)
}
}