什么是[INT]和放大器之间的差异;阵列<&诠释GT ;? [英] What's the difference between [Int] & Array<Int>?

查看:92
本文介绍了什么是[INT]和放大器之间的差异;阵列<&诠释GT ;?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

let numberList = Array(1...10) // type == Array<Int>
let numberList2 = [1,2,3,4,5,6,7,8,9,10] // type == [Int]

上面的code分配注释类型每个常量。我不记得运行到文档中的这个解释。

The code above assigns the commented types to each constant. I don't recall running into an explanation for this in the documentation.

它是简单地使用构造一个的情况下,以及使用的文字符号,另外,其结果的不同类型被生产的?

Is it simply a case of one using the constructor, and the other using literal notation, and as a result the differing types are produced?

如果是这样,在那里用一个比其他,一旦他们被宣布什么不同吗? (即使用构造允许您使用类初始化等,但初始化后,做一件报价比其他任何好处?)

If so, are there any differences to using one over the other, once they've been declared? (i.e. using the constructor allows you to use class initializers etc. but post initialization, does one offer any benefits over the other?)

他们似乎都使用相同的阵列API初始化一次。所以我假定这是所有纯粹的语法?

They seem to both use the same Array API once initialized. So I'm assuming this is all purely syntactical?

最后,有没有办法通过文字符号来模仿构造函数的功能?例如

Lastly, is there any way to mimic the constructors functionality via the literal notation? e.g.

let arr = [](1...10) // doesn't create [1,2,3,4,5,6,7,8,9,10]

有点无关

谁能告诉我,为什么下面的code产生它的结果:

Can anyone tell me why the following code produces the result it does?:

let numberList2 = [1...10] // == ["1..<11"]

我原因,以上是含有范围的阵列。在操场所示类型的报告,该类型是:[范围],符合市场预期。然而,为什么值看似报告为包含字符串重新presenting半开范围高达11的,而不是封闭的范围的阵列高达10?

I reason that the above is an array containing a range. The type shown in a Playground reports that the type is: [Range], as expected. However, why is the value seemingly reported as an array containing a string representing a half-open range up to 11, rather than a closed range up to 10?

有关脱节后道歉。感谢您事先的任何帮助。

Apologies for the disjointed post. Thanks in advance for any help.

推荐答案

从<一个href=\"https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/CollectionTypes.html\"相对=nofollow>雨燕编程语言:集合类型

阵列类型简写语法

A型雨燕阵列是用全为阵列&LT; SOMETYPE&GT; 的,其中SOMETYPE是值类型数组被允许储藏。你也可以写在速记形式的阵列的类型为 [SOMETYPE] 。虽然的这两种形式在功能上是相同的的, - 的简写形式为preferred和本指南是用来的指的是一个数组类型时

The type of a Swift array is written in full as Array<SomeType>, where SomeType is the type of values the array is allowed to store. You can also write the type of an array in shorthand form as [SomeType]. Although the two forms are functionally identical, - the shorthand form is preferred and is used throughout this guide when referring to the type of an array.

也就是说,双方的意见是正确的 - 的两个重present的的相同的类型

That is, both comments are correct - and both represent the same type.

这篇关于什么是[INT]和放大器之间的差异;阵列&LT;&诠释GT ;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆