有简单的代码示例,但我不知道为什么我不检索输出
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)
这是输出
为什么我没有得到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)")