为什么我没有从可选字典的循环中获得输出?

时间:2016-12-12 12:04:06

标签: swift swift3

有简单的代码示例,但我不知道为什么我不检索输出

func printDictOpt (tmp : (Dictionary<String, String>)?) -> (){
for entity in tmp!{
    print("\(entity.key) \(entity.value)")
}
}

var some : [String : String]?
some = [String : String]()

some?["name"] = "Alex"
some?["second"] = "Deeed"

print("count : \(some?.count)")
printDictOpt(tmp: some)

这是输出

enter image description here

为什么我没有得到print()

修改

var some : [String : String]?
some = [String : String]()

some["name"] = "Alex"
some["second"] = "Deeed"

print("count : \(some.count)")

如果我没有将某些标记为可选Xcode,则说我需要添加?

var some : [String : String]?
some = [String : String]()

some?["name"] = "Alex"
some?["second"] = "Deeed"

print("count : \(some?.count)")

0 个答案:

没有答案