0

I would like to use self with an if condition in init() method... (before the super.init()).

Here is my example I can't use (self before super.init) :

init()
{
    if #available(iOS 8.0, *) {
        if self.traitCollection.horizontalSizeClass == .Regular
        {
            super.init(nibName: ProductDetailsIdentifier, bundle: NSBundle.mainBundle())
        }
        else
        {
            super.init(nibName: ProductDetailsIdentifierIphone, bundle: NSBundle.mainBundle())
        }
    }
}

required init?(coder aDecoder: NSCoder)
{
    super.init(coder : aDecoder)
}
Vjardel
  • 1,065
  • 1
  • 13
  • 28
  • Do you perhaps have an [X/Y question](http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem)?. What was the original problem you are trying to solve? It seems like you want to conditionally load a nib for the view, is this correct? – Kevin Oct 30 '15 at 08:56
  • 2
    Is [this answer](http://stackoverflow.com/questions/3052288/dynamically-load-nib-for-iphone-ipad-within-view-controller/9603879#9603879) helpful to you? – Kevin Oct 30 '15 at 08:59
  • The object needs to be initialized first by super class and then you can do your custom initialization – user3441734 Oct 30 '15 at 08:59
  • @Kevin Yes I would like to make an if-statement, to load different xib depending on the size clas – Vjardel Oct 30 '15 at 09:00
  • What is the "size class"? Is it your own custom class? What does it do? What's it's purpose? Does it **have** to be a property in your view controller or can you move it somewhere where the view controller can access it before being done with initialization? – Kevin Oct 30 '15 at 09:01
  • @Kevin Thanks Kevin !!! http://stackoverflow.com/questions/3052288/dynamically-load-nib-for-iphone-ipad-within-view-controller/9603879#9603879 is perfect – Vjardel Oct 30 '15 at 09:02

0 Answers0