一个新手到本地快速发展!
https://github.com/forcedotcom/SalesforceMobileSDK-iOS/issues/2072
使用的移动SDK版本:5.1.0
在本机应用程序或混合应用程序中发现问题:本机应用程序
操作系统版本:10.12.5
设备:iPhone 6
复制步骤:
创造力量
提供的应用程序类型为native_swift并添加其他请求的详细信息
在Xcode中打开*.xcworkspace文件
建设项目
错误: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()
                }
            }
        }

最佳答案

allUserAccountsSFUserAccountManager属性是nullable

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

https://github.com/forcedotcom/SalesforceMobileSDK-iOS/blob/master/libs/SalesforceSDKCore/SalesforceSDKCore/Classes/Security/SFUserAccountManager.h#L188
如果你知道在你试图使用它的时候它将存在,你可以通过输入allAccounts![0]来执行一个力展开。如果您需要处理可能为零的情况,则需要执行以下操作来检查:
if let accounts = allAccounts
{
   currentUser = accounts[0]
}
else
{
   // does not exist
}

我不能告诉你的是,这是否是一个有效的情况,你需要处理,因为我不熟悉图书馆。你需要自己做研究或者问问他们。

关于ios - 构建失败:可选类型“[SFUserAccount]的值?”没有展开,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44377674/

10-14 23:38
查看更多