It is the first time I am going for coordinator pattern. Though I have realised it's importance but there is one major concern I have.
I went through this amazing article on this pattern. As a matter of fact I was able to build a demo project on my own using this. There is one point though - use of Xib is proposed. It is not exclusively mentioned that Storyboards can't be used, but going through these lines towards the end of article, makes me think otherwise :
With great power comes great responsibility (and limitations). To use this extension, you need to create a separate storyboard for each UIViewController. The name of the storyboard must match the name of the UIViewController‘s class. This UIViewController must be set as the initial UIViewController for this storyboard.
It isa mentioned that in case of Storyboards, we should create an extension and use that in UIViewController
:
extension MyViewController: StoryboardInstantiable {
}
StoryboardInstantiable :
import UIKit
protocol StoryboardInstantiable: NSObjectProtocol {
associatedtype MyType // 1
static var defaultFileName: String { get } // 2
static func instantiateViewController(_ bundle: Bundle?) -> MyType // 3
}
extension StoryboardInstantiable where Self: UIViewController {
static var defaultFileName: String {
return NSStringFromClass(Self.self).components(separatedBy: ".").last!
}
static func instantiateViewController(_ bundle: Bundle? = nil) -> Self {
let fileName = defaultFileName
let sb = UIStoryboard(name: fileName, bundle: bundle)
return sb.instantiateInitialViewController() as! Self
}
}
Queries :
- As the author mentioned that separate Storyboard would have to be created for each
UIViewController
, how is using Xib a better way in Coordinator pattern ? - Why do we need to create a separate Storyboard for each
UIViewController
? Can't we useUIViewController
's storyboard identifier for that by not linking anyUIViewController
using segues ? That way can adjust the above extension using identifier and easily achieve the same.