Uday Veer Singh Patial Uday Veer Singh Patial - 19 days ago 5
Swift Question

swift 3 error xcode 8.1 while assigning rootviewcontroller says it is a get-only property

I was migrating my project from swift 2.2 to 3.0, when I reached a point where I get this strange error, which does not allow me to set rootviewcontroller in the app delegate didfinishlaunching.
self.window?.rootViewController = self.container.resolve(DPSlideMenuController.self)!
enter image description here

Answer

Finally fixed it. The issue was there was a var named rootViewController in one of the protocol extension.

var rootViewController: UIViewController {
        return (UIApplication.shared.keyWindow?.rootViewController)!
    }

Was working fine with Swift 2.2, but on swift 3 was confusing the compiler. Changed the name and the code got compiled.

Comments