Custom init for UIViewController in Swift with interface setup in storyboard : <p>I'm having issue for writing custom init for subclass of UIViewController, basically I want to pass the dependency through the init method for viewController rather than setting property directly like <code>viewControllerB.property = value</code></p>

<p>So I made a custom init for my viewController and call super designated init</p>

<pre><code>init(meme: Meme?) {
        self.meme = meme
        super.init(nibName: nil, bundle: nil)
    }
</code></pre>

<p>The view controller interface resides in storyboard, I've also make the interface for custom class to be my view controller. And Swift requires to call this init method even if you are not doing anything within this method. Otherwise the compiler will complain...</p>

<pre><code>required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
</code></pre>

<p>The problem is when I try to call my custom init with <code>MyViewController(meme: meme)</code> it doesn't init properties in my viewController at all...</p>

<p>I was trying to debug, I found in my viewController, <code>init(coder aDecoder: NSCoder)</code> get called first, then my custom init get called later. However these two init method return different <code>self</code> memory addresses.</p>

<p>I'm suspecting something wrong with the init for my viewController, and it will always return <code>self</code> with the <code>init?(coder aDecoder: NSCoder)</code>, which, has no implementation.</p>

<p>Does anyone know how to make custom init for your viewController correctly ? 
Note: my viewController's interface is set up in storyboard</p>

<p>here is my viewController code:</p>

<pre><code>class MemeDetailVC : UIViewController {

    var meme : Meme!

    @IBOutlet weak var editedImage: UIImageView!

    // TODO: incorrect init
    init(meme: Meme?) {
        self.meme = meme
        super.init(nibName: nil, bundle: nil)
    }

    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }

    override func viewDidLoad() {
        /// setup nav title
        title = "Detail Meme"

        super.viewDidLoad()
    }

    override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)
        editedImage = UIImageView(image: meme.editedImage)
    }

}
</code></pre>
