gpt4 book ai didi

ios - 构建失败 : Value of optional type '[SFUserAccount]?' not unwrapped

转载 作者:行者123 更新时间:2023-11-28 15:35:01 24 4
gpt4 key购买 nike

原生快速开发的新手!
https://github.com/forcedotcom/SalesforceMobileSDK-iOS/issues/2072 中打开了以下问题

使用的移动 SDK 版本: 5.1.0
在原生应用或混合应用中发现的问题:原生应用
操作系统版本: 10.12.5
设备: iPhone 6
重现步骤:

  • forceios 创建
  • 提供的应用程序类型为 native_swift并添加其他要求的详细信息
  • 打开*.xcworkspace Xcode 中的文件
  • 构建项目

  • 错误: Value id optional type '[SFUserAccount]?' not unwrapped;
        func handleSdkManagerLogout()
    {
    self.log(.debug, msg: "SFAuthenticationManager logged out. Resetting app.")
    self.resetViewState { () -> () in
    self.initializeAppViewState()

    // Multi-user pattern:
    // - If there are two or more existing accounts after logout, let the user choose the account
    // to switch to.
    // - If there is one existing account, automatically switch to that account.
    // - If there are no further authenticated accounts, present the login screen.
    //
    // Alternatively, you could just go straight to re-initializing your app state, if you know
    // your app does not support multiple accounts. The logic below will work either way.

    var numberOfAccounts : Int;
    let allAccounts = SFUserAccountManager.sharedInstance().allUserAccounts()
    numberOfAccounts = (allAccounts!.count);

    if numberOfAccounts > 1 {
    let userSwitchVc = SFDefaultUserManagementViewController(completionBlock: {
    action in
    self.window!.rootViewController!.dismiss(animated:true, completion: nil)
    })
    if let actualRootViewController = self.window!.rootViewController {
    actualRootViewController.present(userSwitchVc!, animated: true, completion: nil)
    }
    } else {
    if (numberOfAccounts == 1) {
    SFUserAccountManager.sharedInstance().currentUser = allAccounts[0]

    // ERROR: Value id optional type '[SFUserAccount]?' not unwrapped;
    }
    SalesforceSDKManager.shared().launch()
    }
    }
    }

    最佳答案

    allUserAccounts SFUserAccountManager 的属性(property)是 nullable .

    - (nullable NSArray <SFUserAccount *> *) allUserAccounts;

    https://github.com/forcedotcom/SalesforceMobileSDK-iOS/blob/master/libs/SalesforceSDKCore/SalesforceSDKCore/Classes/Security/SFUserAccountManager.h#L188

    如果您知道它在您尝试使用它时会存在,您可以通过键入 allAccounts![0] 执行强制展开。 .如果您需要处理它可能为 nil 的情况,您需要通过执行以下操作来检查它:
    if let accounts = allAccounts
    {
    currentUser = accounts[0]
    }
    else
    {
    // does not exist
    }

    我不能告诉你的是它是否是 nil 实际上是你需要处理的有效案例,因为我不熟悉这个库。您需要自己进行研究或询问他们。

    关于ios - 构建失败 : Value of optional type '[SFUserAccount]?' not unwrapped,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44377674/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com