判断是否为空

使用的是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. 42.OC中instancetype与id的区别

    区别: 在ARC(Auto Reference Count)环境下: instancetype用来在编译期确定实例的类型,而使用id的话,编译器不检查类型,运行时检查类型 在MRC(Manual Re ...

  2. springboot xml声明式事务管理方案

    在开发过程中springboot提供的常见的事务解决方案是使用注解方式实现. 使用注解 在启动类上添加注解 @EnableTransactionManagement 在需要事务控制的方法添加@Tran ...

  3. java socket之传输实体类对象

    一.TCP编程     TCP协议是面向连接的.可靠地.有序的,以字节流的方式发送数据.java实现TCP通信依靠2个类:客户端的Socket类和服务器端的ServerSocket类. 基于TCP通信 ...

  4. 安卓修改开机logo和开机动画的方法

    第一种和第二种方法亲测可用,安卓版本是4.2和安卓5.1均可.第二种方法待验证 以下三种方法 Android 开机其实总共会出现3个画面: 1.第一个就是 linux 系统启动,出现Linux小企鹅画 ...

  5. 主机网络ping: unknown host baidu.com问题解决

    本机环境: 系统:Centos 网络:NAT 虚拟机之前一直都可以连外网,但最近不能连了,现状如下: [root@vhost03 ~]# ping baidu.comping: unknown hos ...

  6. AngularJS中$interval和$timeout的使用

    我们在项目中会出现定时刷新,延迟加载等多种场景. 接下来就看$interval和$timeout的使用 $interval可用于定时任务,我们只需在controller注入$interval即可使用. ...

  7. python(1)在windows8.1下搭建python27和python36环境

    去Python官网下载需要的Python版本 https://www.python.org/ 我下载的是下面这两个版本: Python 2.7.13 Python 3.6.1 安装Python27时, ...

  8. Linux入门(9)——Ubuntu16.04安装flash player

    打开网页经常提示安装flash player,不安装flash player很多网页的视频都看不了. Ubuntu16.04安装flash player 打开终端,输入: sudo apt-get i ...

  9. AFNetworking网络请求数据

    //创建AFNetworking的请求操作    AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWit ...

  10. spring整合redis之hello

    1.pom.xml文件 <dependencies> <!-- spring核心包 --> <dependency> <groupId>org.spri ...