I am getting the following error when trying to archive my build on XCode:
/Users/AppDelegate.swift:18:9: 'guard' body may not fall through, consider using 'return' or 'break' to exit the scope
It is a little frustrating, because it is the exact code that Google Analytics (I just copied/pasted) suggests you to put in appdelegate to set-up their analytics. Also, it only occurs when archiving my build. It does not occur when just running my code in the simulator.
Would appreciate if anyone had some ideas.
EDIT: I also tried placing a break or continue after the assert, but I got an error...Something about it not being a loop.
import UIKit
import Firebase
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
FIRApp.configure()
//Google Analytics
guard let gai = GAI.sharedInstance() else {
assert(false, "Google Analytics not configured correctly")
}
gai.tracker(withTrackingId: "xxxxxxxxxxx")
// Optional: automatically report uncaught exceptions.
gai.trackUncaughtExceptions = true
// Optional: set Logger to VERBOSE for debug information.
// Remove before app release.
gai.logger.logLevel = .verbose;
return true
}
guard let
function needs to exit the current scope of your gai
variable. So you need to modify your code to
guard let gai = GAI.sharedInstance() else {
assert(false, "Google Analytics not configured correctly")
return true//Base on your function return type, it may be returning something else
}
Here is the document:
The else clause of a guard statement is required, and must either call a function marked with the noreturn attribute or transfer program control outside the guard statement’s enclosing scope using one of the following statements:
return break continue throw
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With