Abhinay Reddy Keesara
Abhinay Reddy Keesara

Reputation: 10141

Xcode showing multiple warnings in AppDelegate after updating to version 8?

I had updated my Xcode 7.3 to Xcode 8.

It is showing multiple warnings in AppDelegate. The warning is as follows.

Extraneous '_' in parameter: 'application' has no keyword argument name

My AppDelagate.swift file is this:

import UIKit

@UIApplicationMain

class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?


    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        return true
    }

    func applicationWillResignActive(_ application: UIApplication) {
        // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
        // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
    }

    func applicationDidEnterBackground(_ application: UIApplication) {
        // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
        // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
    }

    func applicationWillEnterForeground(_ application: UIApplication) {
        // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
    }

    func applicationDidBecomeActive(_ application: UIApplication) {
        // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
    }

    func applicationWillTerminate(_ application: UIApplication) {
        // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
    }


}

when I followed the Xcode suggestion to remove _ in the functions that shows warning.

I got rid of the above warning. But now I get a new warning for

 func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        return true
    }

The warning is:

Non-@objc method 'application(_:didFinishLaunchingWithOptions:)' cannot satisfy optional requirement of @objc protocol 'UIApplicationDelegate'

I followed the solutions online. But had no luck in getting rid of this warning.

Any help would be appreciated. Thanks.

Upvotes: 0

Views: 432

Answers (1)

matt
matt

Reputation: 535765

Your code is correct for Swift 3. But the environment you are in clearly thinks it is supposed to be Swift 2, and that is the reason for the error messages.

It sounds as if you have accidentally opened the file in Xcode 7. That would explain it. Your code is now Swift 3. Xcode 7 is Swift 2; it does not know about Swift 3 and doesn't understand your code. Now that you have converted to Swift 3, you can never use Xcode 7 with this project ever again.

Or maybe this is Xcode 8 but the legacy build setting is still on, so it thinks this is supposed to be Swift 2. But it isn't. It is Swift 3.

Upvotes: 3

Related Questions