判断是否为空

使用的是Collection协议里isEmpty的判断。

  public var isEmpty: Bool {
return startIndex == endIndex
}

startIndex 总是返回 0

  public var startIndex: Int {
return 0
}

endIndex代码如下:

  @inlinable
public var endIndex: Int {
@inlinable
get {
return _getCount()
}
}

最终用到了_ContiguousArrayStorage类里的countAndCapacity 变量。

  internal var count: Int {
get {
return _storage.countAndCapacity.count
}
nonmutating set {
_internalInvariant(newValue >= 0) _internalInvariant(
newValue <= capacity,
"Can't grow an array buffer past its capacity") _storage.countAndCapacity.count = newValue
}
}

确定长度

  /// The number of elements in the array.
@inlinable
public var count: Int {
return _getCount()
}

在确定isEmpty时提到过。

capacity

  /// The number of elements the buffer can store without reallocation.
@inlinable
internal var capacity: Int {
return _storage.countAndCapacity.capacity
}

用到了_ContiguousArrayStorage类里的countAndCapacity 变量。

Swift 里 Array (三) Inspecting an Array的更多相关文章

  1. [Swift]LeetCode665. 非递减数列 | Non-decreasing Array

    Given an array with n integers, your task is to check if it could become non-decreasing by modifying ...

  2. C#编程(三十三)----------Array类

    Array类 创建数组 Array intArray1 = Array.CreateInstance(typeof(int), 5); for (int i = 0; i < 5; i++) { ...

  3. iOS开发Swift篇—(三)字符串和数据类型

    iOS开发Swift篇—(三)字符串和数据类型 一.字符串 字符串是String类型的数据,用双引号""包住文字内容  let website = "http://www ...

  4. [Swift通天遁地]三、手势与图表-(5)创建带有标题、图例、坐标轴的柱形图表

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  5. [Swift通天遁地]三、手势与图表-(6)创建包含三条折线的线性图表

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  6. [Swift通天遁地]三、手势与图表-(9)制作五彩缤纷的气泡图表

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  7. [Swift通天遁地]三、手势与图表-(10)创建包含圆点、方形、三角形图标的散点图表

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  8. [Swift通天遁地]三、手势与图表-(11)制作雷达图表更加形象表示各个维度的情况

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  9. Swift中文教程(三)--流程控制

    原文:Swift中文教程(三)--流程控制 Swift用if和switch编写条件控制语句,用for-in,for,while和do-while编写循环.条件控制语句和循环语句中,小括号是可选的,但花 ...

  10. 观V8源码中的array.js,解析 Array.prototype.slice为什么能将类数组对象转为真正的数组?

    在官方的解释中,如[mdn] The slice() method returns a shallow copy of a portion of an array into a new array o ...

随机推荐

  1. 2019.01.21 bzoj3674: 可持久化并查集加强版(主席树+并查集)

    传送门 题意:维护可持久化并查集,支持在某个版本连边,回到某个版本,在某个版本 询问连通性. 思路: 我们用主席树维护并查集fafafa数组,由于要查询历史版本,因此不能够用路径压缩. 可以考虑另外一 ...

  2. CLE的使用笔记

    CLE官网http://www.srplab.com/cn/index.html 下载CLE for Android,解压文件,拷贝 starcore_android_rX.X.jar到工程的libs ...

  3. LPCSTR与CString转换

    1.LPCSTR是Win32和VC++所使用的一种字符串数据类型,L表示long,P表示指针,C表示常量,STR表示字符串. 2.LPCSTR转化为CString: LPCSTR  lpStr=&qu ...

  4. 在多台PC之间同步Resharper所有设置的方法

    默认情况下Resharper只允许导出CodeStyle的设置,对于其它的设置不能导出,这样在不利用我们在多台PC之间同步Resharper的设置,经过多次尝试和Google找到了一种解决办法: Re ...

  5. SQL常用增删改查

    转 http://www.cnblogs.com/daxueshan/p/6687521.html 1增 1.1[插入单行]insert [into] <表名> (列名) values ( ...

  6. leetcode - [2]Evaluate Reverse Polish Notation

    Evaluate Reverse Polish Notation Total Accepted: 24595 Total Submissions: 123794My Submissions Evalu ...

  7. leetcode - [1]Reverse Words in a String

    Question: Reverse Words in a String Given an input string, reverse the string word by word. For exam ...

  8. ssh+注解开发 pom.xml

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...

  9. java实现在图片上编辑文本内容

    package com.yin.text; import java.awt.Color; import java.awt.Font; import java.awt.Graphics2D; impor ...

  10. codeforces815A Karen and Game 2017-06-27 15:22 31人阅读 评论(0) 收藏

    C. Karen and Game time limit per test 2 seconds memory limit per test 512 megabytes input standard i ...