iOS swift 仅在归档时出现编译错误

iOS swift compilation error only when archiving

我收到以下错误

AppDelegate.swift:152:30: '(appToken: String!) -> SKTSettings' is not convertible to '(appToken: String!) -> SKTSettings!'

AppDelegate.swift:167:23: '(writeKey: String!) -> SEGAnalyticsConfiguration' is not convertible to '(writeKey: String!) -> SEGAnalyticsConfiguration!'

违规台词

let smoochSettings = SKTSettings(appToken: "xxxxx") let config = SEGAnalyticsConfiguration(writeKey: "xxxx")

任何线索,我不明白...

有关代码的更多上下文

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

    setupToast()

    //setup rollbar
    let rollbarConfig: RollbarConfiguration = RollbarConfiguration()

    #if RELEASE
        rollbarConfig.environment = "production"
    #elseif ADHOC
        rollbarConfig.environment = "adhoc"
    #else
        rollbarConfig.environment = "development"
    #endif

    Rollbar.initWithAccessToken("xxx", configuration: rollbarConfig, enableCrashReporter: false)

    AFNetworkReachabilityManager.sharedManager().startMonitoring()
    AFNetworkReachabilityManager.sharedManager().setReachabilityStatusChangeBlock { status in
        switch status {
        case .NotReachable:
            self.SHOW_ERROR("La connexion internet semble interrompue", completion: nil)
            break
        default:
            CRToastManager.dismissAllNotifications(true)
            break
        }
    }

    ParseManager.initParse()
    LBStripeManager.initStripe()
    loadAppearances()
    //FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
    PFFacebookUtils.initializeFacebookWithApplicationLaunchOptions(launchOptions)
    FBSDKProfile.enableUpdatesOnAccessTokenChange(true)

    GMSServices.provideAPIKey("xxx")
    GMSPlacesClient.provideAPIKey("xxx")
    NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(AppDelegate.loadAppearances), name: "switchUserType", object: nil)
    let branch = Branch.getInstance()
    branch.initSessionWithLaunchOptions(launchOptions, andRegisterDeepLinkHandler: { params, error in

        if params["fromUserId"] != nil {
            let senderId = params["fromUserId"]!
            SEGAnalytics.sharedAnalytics().track("Refferal", properties: ["branchFromUser": senderId])
        }

        if params["adId"] != nil {
            let adId = params["adId"] as! String
            NSNotificationCenter.defaultCenter().postNotificationName("adCreated", object: nil)
            AdManager.sharedInstance.showAdToBabysitterFromRemoteNotification(adId, presentingController: self.window!.rootViewController!)
        }

        if (error == nil) {
            DeepLinkManager.handleDeepLinkWithParams(params)
            DeepLinkManager.sharedInstance.alreadyGotANetworkError = false
        } else if !DeepLinkManager.sharedInstance.alreadyGotANetworkError && DeepLinkManager.sharedInstance.isLoadingDataFromBranchServer {
            DeepLinkManager.sharedInstance.alreadyGotANetworkError = true
            UIWindow.topViewController().hideHUD(false)
            var errorMessage = PFConfig.stringForKey("inviteNoInternetAlertMessage")
            if errorMessage.isEmpty {
                errorMessage = "Vous n'êtes actuellement pas connecté à Internet. Le parrainage reprendra automatiquement dès qu'Internet sera disponible."
            }
            UIWindow.topViewController().showAlert(message: errorMessage)
        }
    })

    initSiren()

    // fabric
    Crashlytics().debugMode = false
    Fabric.with([Crashlytics.self])
    logUserInFabric()

    // smooch
    let smoochSettings = SKTSettings(appToken: "xxxxx")

    smoochSettings.userId = PFUser.currentUser()?.objectId
    Smooch.initWithSettings(smoochSettings)

    // intercom
    Intercom.setApiKey("xxx", forAppId: "xxxx")
    AppDelegate.phoneForCurrentUser()

    if needToSendSmoochLastOpenTag() {
        SKTUser.currentUser().addProperties(["DELTA_USAGE": "true"])
    }

    NSUserDefaults.standardUserDefaults().setObject(NSDate().timeIntervalSince1970, forKey: "LastOpen")


    var config = SEGAnalyticsConfiguration(writeKey: "xxx")
    #if RELEASE
    config.flushAt = 15
    #else
    config.flushAt = 1
    #endif
    SEGAnalytics.setupWithConfiguration(config)

    return true
}

更新 将 SDK 更新到版本 5.0.1 将解决此问题

here 所述,更新到 XCode 8 后,Swift 编译器无法正确确定这些值是否可选。将可空性说明符添加到 Smooch 头文件应该可以解决这个问题。带有可空性说明符的版本正在开发中,应该会很快发布。