一些Swift 4代码不会在不同的iPhone版本中执行

时间:2018-01-17 15:55:17

标签: ios10 ios11 swift4

所以,我有一些代码必须在相当范围的iPhone版本中运行,从5s到8和8+,最小的iOS版本是iOS 10.这些代码假设根据用户登录状态显示一些菜单项。如果有用户登录,则假设显示如下菜单:

boxes them into java.lang.Integer

如果没有,它假设显示如下菜单:

if there was a user logged in

以下是代码:

    if let LoginStatus = userdefault.value(forKey: "loginStatus") as? Bool {
            if LoginStatus { //if there is a user login, do these things
                iconMenu = ["icoFeatured", "icoOrder", "icoReward", "icoPayment", "icoReferral", "icoSupport", "icoSettings"]
                titleMenu = ["Featured", "Order History", "Reward Cards", "Payment Methods", "Referral Code", "Support", "Settings"]
                titleMenu2 = ["About", "Logout"]
            } else { //if there is NO user login, do these things
                iconMenu = ["icoFeatured", "icoSupport", "icoSettings", "icoClose"]
                titleMenu = ["Featured", "Support", "Settings", "Crash Test"]
                titleMenu2[titleMenu2.count-1] = "Login/Register"
            }
        }

当我使用6/6 +,6s / 6s +,7/7 +和8/8 +进行测试时,一切都还可以,但是当我使用5s进行测试时,它不会执行我的可选绑定

 if let LoginStatus = userdefault.value(forKey: "loginStatus") as? Bool {...}

我想知道,它怎么会发生?安装iOS10及更高版本时,iPhone 5s应能正确执行Swift 4代码,不是吗?如果有人能帮助我弄清楚这一点,我真的很感激。

0 个答案:

没有答案