I'm quite new to Swift and want to know the difference between [String!]
and [String]!
. Both are non optional? but [String]!
indicates nil
when uninitialized and [String!]
does not?
[String!]
is an array of implicitly unwrapped String
s
[String]!
is an implicitly unwrapped array of String
s
That means that the first one can contain nil
values but cannot itself be nil
. The second one could itself be nil
but its contents are always non- nil
.
This is an array of Implicitly Unwrapped Strings
.
It means that in each element of this array you could find a
String
ornil
.
let list0: [String!] = ["Hello", nil, "world", nil]
This is an Implicitly Unwrapped Array
that contains String
.
It means that in a variable declared like this you can find
nil
or an array where every element is a validString
.
let list1: [String]! = nil
let list2: [String]! = ["Hello", "world"]
[String!]
- this is a non optional array of optional Strings
.
[String]!
- this is a optional array of non optional Strings
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.