2016-02-05 57 views
0
array = [ 
    “test” = test 
    “test1” = test 
    “test2” = test 
    “test4” = test 
] 

检查TEST3是阵列中斯威夫特:检查空数组

我试着这样做:

if let check= userObject[“test3”]{ 

} 

我的应用程序崩溃,我得到这个错误:意外发现零而展开的可选值

+2

是不是你的数组声明错误? – sasquatch

回答

1

您需要用逗号分隔对象,这是一个字典,而不是数组。

var dict: [String: AnyObject] = [:] 

dict = [ 
    "test": test, 
    "test1": test, 
    "test2": test, 
    "test4": test 
]