【发布时间】:2017-06-27 18:01:37
【问题描述】:
尝试在 XCode 上存档我的构建时出现以下错误:
/Users/AppDelegate.swift:18:9: 'guard' body 可能不会掉下来, 考虑使用 'return' 或 'break' 退出范围
这有点令人沮丧,因为它是 Google Analytics(我刚刚复制/粘贴)建议您放入 appdelegate 以设置其分析的确切代码。此外,它仅在归档我的构建时发生。仅在模拟器中运行我的代码时不会发生。
如果有人有一些想法,将不胜感激。
编辑:我也尝试在断言之后放置一个中断或继续,但我得到了一个错误......关于它不是一个循环的东西。
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
}
【问题讨论】:
-
请参阅stackoverflow.com/a/29149643/1187415,了解为什么该错误仅发生在“存档”版本而不是“调试”版本中。
-
您应该使用
assertionFailure而不是assert(false,...),但不幸的是,assertionFailure不会返回Never,这将满足保护语句退出作用域的要求。 -
@Alexander:与 fatalError() 相比,“-O”构建中也忽略了 assertionFailure。
-
@MartinR 很有趣。你能想出一个
assertionFailure更可取的用例吗? -
即使 Google Analytics 无法初始化,您也可能希望已发布的应用程序运行。
标签: ios swift xcode google-analytics