user7770817
user7770817

Reputation: 81

Class AppDelegate has no initializers

I downloaded sample code from here for a location tracking application https://www.pubnub.com/blog/2015-05-05-getting-started-ios-location-tracking-and-streaming-w-swift-programming-language/. I am trying to run the application but in the AppDelegate class I am getting an error saying "Class AppDelegate has no initializers". What is causing this error and how can I fix it?

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    // MARK: - Properties
    //var window: UIWindow?
    var window = UIWindow(frame: UIScreen.mainScreen().bounds)

    // MARK: - App Life Cycle

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

        // Adding a Navigation Controller and tool bar
        self.window.rootViewController = UINavigationController(rootViewController: MainViewController(nibName: nil, bundle: nil))

        // Make window visible
        self.window.makeKeyAndVisible()

        return true
    }
}

Upvotes: 0

Views: 1332

Answers (1)

GetSwifty
GetSwifty

Reputation: 377

I would set the window to be an optional value with no default. just as you originally had then commented out

var window: UIWindow?

then give window a value and programmatically add the root view controller when your app launches

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
let viewController = ViewController(nibName: nil, bundle: nil) //ViewController = Name of your controller
let navigationController = UINavigationController(rootViewController: viewController)

self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
self.window?.rootViewController = navigationController
self.window?.makeKeyAndVisible()

return true

}

Upvotes: 1

Related Questions