[英]What's the difference between [String!] and [String]!
I'm quite new to Swift and want to know the difference between [String!]
and [String]!
我对Swift很新,想知道
[String!]
和[String]!
之间的区别[String]!
. 。 Both are non optional?
两者都不是可选的? but
[String]!
但是
[String]!
indicates nil
when uninitialized and [String!]
does not? 未初始化时指示
nil
, [String!]
不指示?
[String!]
is an array of implicitly unwrapped String
s [String!]
是一个隐式解包的String
数组
[String]!
is an implicitly unwrapped array of String
s 是一个隐式解包的
String
数组
That means that the first one can contain nil
values but cannot itself be nil
. 这意味着第一个可以包含
nil
值,但本身不能nil
。 The second one could itself be nil
but its contents are always non- nil
. 自己第二个可能是
nil
,但它的内容始终不nil
。
This is an array of Implicitly Unwrapped Strings
. 这是一个
Implicitly Unwrapped Strings
数组。
It means that in each element of this array you could find a
String
ornil
.这意味着在这个数组的每个元素中你可以找到一个
String
或nil
。
let list0: [String!] = ["Hello", nil, "world", nil]
This is an Implicitly Unwrapped Array
that contains String
. 这是一个包含
String
的Implicitly Unwrapped Array
。
It means that in a variable declared like this you can find
nil
or an array where every element is a validString
.这意味着在这样声明的变量中,您可以找到
nil
或数组,其中每个元素都是有效的String
。
let list1: [String]! = nil
let list2: [String]! = ["Hello", "world"]
[String!]
- this is a non optional array of optional Strings
. [String!]
- 这是一个可选Strings
的非可选数组。
[String]!
- this is a optional array of non optional Strings
. - 这是一个可选的非可选
Strings
数组。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.