Skip to content

Inherit from EPUBNavigatorViewController? #407

Answered by mickael-menu
domkm asked this question in Q&A
Discussion options

You must be logged in to vote

I wouldn't rely on inheritance when it's not explicitly designed for in the toolkit. Inheritance can be tricky and lead to hard-to-find bugs if you override things incorrectly. So it's preferable to use composition over inheritance.

Here's the recommended way to catch events from the responder chain, such as a highlight event:

class ReaderViewController<N: UIViewController & Navigator>: UIViewController {
    let navigator: N

    init(navigator: N) {
        self.navigator = navigator
        super.init(nibName: nil, bundle: nil)
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()

        addChild(navigator)
        navigator.view.frame = view.bounds
        navigator.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@domkm
Comment options

Answer selected by domkm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants