swift语言点评十二-Subscripts
Classes, structures, and enumerations can define subscripts, which are shortcuts for accessing the member elements of a collection, list, or sequence.
下标的形式和函数相同,并且set和get合一
subscript(row: Int, column: Int) -> Double
比较:
In addition to simple properties that are stored, properties can have a getter and a setter.
class EquilateralTriangle: NamedShape {var sideLength: Double = 0.0init(sideLength: Double, name: String) {self.sideLength = sideLengthsuper.init(name: name)numberOfSides = 3}var perimeter: Double {get {return 3.0 * sideLength}set {sideLength = newValue / 3.0}}override func simpleDescription() -> String {return "An equilateral triangle with sides of length \(sideLength)."}}var triangle = EquilateralTriangle(sideLength: 3.1, name: "a triangle")print(triangle.perimeter)triangle.perimeter = 9.9print(triangle.sideLength)
swift语言点评十二-Subscripts的更多相关文章
- swift语言点评十四-继承
Overriding A subclass can provide its own custom implementation of an instance method, type method, ...
- swift语言点评十九-类型转化与检查
1.oc比较: -(BOOL) isKindOfClass: classObj判断是否是这个类或者这个类的子类的实例 -(BOOL) isMemberOfClass: classObj 判断是否是这个 ...
- swift语言点评十八-异常与错误
1.错误类型与枚举的结合 enum VendingMachineError: Error { case invalidSelection case insufficientFunds(coinsNee ...
- swift语言点评十-Value and Reference Types
结论:value是拷贝,Reference是引用 Value and Reference Types Types in Swift fall into one of two categories: f ...
- swift语言点评十六-Initialization && Deinitialization
initial value:必须初始化.不影响观察者 Classes and structures must set all of their stored properties to an appr ...
- swift语言点评十五-$0
import UIKitimport XCPlayground class ViewController: UIViewController { func action() { print(" ...
- Swift语言指南(十)--字符串与字符
原文:Swift语言指南(十)--字符串与字符 字符串是一段字符的有序集合,如"hellow,world"或"信天翁".Swift 中的字符串由 String ...
- C语言第十二讲,文件操作.
C语言第十二讲,文件操作. 一丶文件操作概述 在操作系统中,我们的文档都称为文件.操作系统也为我们提供了接口进行操作.不同语言都是使用的相同的接口,只不过封装的上层接口不一样 操作文件的步骤 打开文件 ...
- IOS系列swift语言之课时二
今天我们要讲的就是函数[对于函数,在最后面还有几道题,喜欢的博友可以看了自己做一下,和我交流一下] 当然这与我们的c语言还是有一定的共同之处的,对于有一些c语言或者是java基础的童鞋,我觉得是很容易 ...
随机推荐
- ndis6 how to drop packets
In ndis6 how to drop packets? in FilterSendNetBufferLists: FILTER_RELEASE_LOCK(&pFilter->Lock ...
- const使用总结
1.常变量: const 类型说明符 变量名 const int a; 常引用: const 类型说明符 &引用名 const int &a; 常对象: 类名 cons ...
- web.xml中的url-pattern写法规则及匹配过程
servlet和filter在javaEE开发中很常用,因此有必要知道web.xml文件映射的规则 1. 写法 ①完全匹配:以“/”开头,以字母(非“*”)结束 如:<url-patte ...
- POJ 2524 Ubiquitous Religions 【并查集】
解题思路:输入总人数 n,和m组数据:即和杭电畅通工程相类似,对这m组数据做合并操作后,求最后一共有多少块区域. #include<stdio.h> int pre[50001]; int ...
- Tensorflow学习笔记----模型的保存和读取(4)
一.模型的保存:tf.train.Saver类中的save TensorFlow提供了一个一个API来保存和还原一个模型,即tf.train.Saver类.以下代码为保存TensorFlow计算图的方 ...
- vim配置C++开发环境 win10
资料一 —— vim插件的安装 https://www.cnblogs.com/tianzhiyi/p/5338032.html 资料二 —— vim多窗口操作: https://blog.csdn. ...
- python_传递任意数量的实参
'''def name(*args): #python创建一个空元组,将收到的所有值都封装在这个元组中 """打印所有姓名""" for i ...
- 如何使用JAVA请求HTTPS
JDK对应的TLS版本(仅供参考) 1.写一个SSLClient类,继承至HttpClient import java.security.cert.CertificateException; impo ...
- 移动端ios兼容问题
IOS系统bug: 1)input无法输入的问题: -webkit-user-select:none;改成-webkit-user-select:auto: 2)滚动不流畅(overflow-y:au ...
- libvips
libvips : an image processing library libvips is a 2D image processing library. Compared tosimilar l ...