在Swift中,如果一个类型被括起来是什么意思,例如。 "(字符串)"

时间:2015-01-19 21:20:44

标签: swift

简单的问题,很难谷歌,不记得在文档中看到这一点。下面的代码将变量显示为“(String)”而不仅仅是“String”这是什么意思?

var myDictionary = [String:Bool]()
// put whatever data you want in there, for example
myDictionary["cat"] = true
var firstKey = [String](myDictionary.keys)[0] //firstKey is type (String) as opposed to "String"
var myString = "this is my string" // has type String
var myOptionalString: String?  // has type String?
var myUninitializedString: String!  // has type String!

我想这可能与推断类型有关?

屏幕截图(从代码完成窗口,检查类型的快速方法):screenshot of (String)

由于

1 个答案:

答案 0 :(得分:2)

这意味着它是一个单元素元组,其行为与同一类型的非元组完全相同。别担心。