简体   繁体   English

[String!]和[String]之间有什么区别!

[英]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

[String!] [串!]

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 or nil . 这意味着在这个数组的每个元素中你可以找到一个Stringnil

let list0: [String!] = ["Hello", nil, "world", nil]

[String]! [串]!

This is an Implicitly Unwrapped Array that contains String . 这是一个包含StringImplicitly Unwrapped Array

It means that in a variable declared like this you can find nil or an array where every element is a valid String . 这意味着在这样声明的变量中,您可以找到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.

相关问题 可选:[String?]和[String]有什么区别? - Optionals: What's the difference between [String?] and [String]? [Dictionary和有什么不一样 <String, String> ()]和[String:String]() - What is the difference between [Dictionary<String, String>()] and [String: String]() Swift 中的 [[String:String]]: 和 [[String:String]]() 有什么区别 - What is the difference between [[String:String]]! and [[String:String]]() in Swift swift中“as string”和“stringvalue”有什么区别? - What is the difference between “ as string” and “stringvalue” in swift? String和有什么不一样? 和弦! (创建可选变量的两种方式)? - What is the difference between String? and String! (two ways of creating an optional variable)? Swift`= String()`和`:String!`中的2个字符串初始化有什么区别? - What is the difference between 2 strings initialization in Swift `=String()` and `: String!` Swift错误消息中的&#39;(String)&#39;和&#39;String&#39;有什么区别 - What is the difference between '(String)' and 'String' in a Swift error message swift中的:和=有什么区别 - What's the difference between : and = in swift 旋转速度和姿态有什么区别? - What's the difference between rotation rate and attitude? FBTweakBind和FBTweakValue有什么区别? - What's the difference between FBTweakBind and FBTweakValue?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM