【问题标题】:Swift: check empty arraySwift:检查空数组
【发布时间】:2016-02-05 10:03:37
【问题描述】:
array = [
    “test” = test
    “test1” = test
    “test2” = test  
    “test4” = test  
]

检查test3是否在数组中

我尝试过这样做:

if let check= userObject[“test3”]{

}

我的应用程序崩溃并出现此错误:在展开可选值时意外发现 nil

【问题讨论】:

  • 你的数组声明没有出错吗?

标签: arrays swift arraylist


【解决方案1】:

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-01-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-04
    • 2011-01-14
    • 2010-10-18
    相关资源
    最近更新 更多