我很困惑,因爲我在兩個ViewControllers之間傳遞了一個參數Notification
。我不是嘗試使用盡可能Bool
傳遞給前進參數:來自Notification Dictionary Any或Bool的參數?
func doWhenParameterSelected(notification: Notification) {
let status = notification.userInfo!["key0"]!
print(type(of:status)) //is "Bool" in Console
print(status) // value is "true" or "false" in Console
if status {... // error occurs "'Any' is not convertible to 'Bool'"
我總是得到錯誤信息'Any' is not convertible to 'Bool'
。
那麼,爲什麼在控制檯中爲status
Any
時type(of: status))
爲Bool
。如果Any
類型如何使用status
作爲Bool
類型?
謝謝!
你能做到在一個單一的step'if讓狀態= notification.userInfo![ 「KEY0」]作爲?布爾' – Russell
是的問題更新,並感謝評論。 @Russell –