1. 枚举: ->在Swift中依然适用整数来标示枚举值,需搭配case关键字 enum Celebrity{ case DongXie,XiDu,Nandi,BeiGai } // 从左到右对应0,1,2,3 enum CompassPoint { case North case South case East case West //enum中可以定义方法 func show(){ print(self) } } //定义enum 变量 var p = CompassPoint.Nor…
//: Playground - noun: a place where people can play import Cocoa var str = "Hello, playground" //这里先提及下, //Swift中的属性的定义 //属性名首字母只能是字母,下划线 //首字母后也只能是数字,字母,下划线 /****************************************常量与变量**/ /**************常量的定义*/ //语法上就是使用let关…
类.结构体和枚举可以定义下标,他可以快速简单地访问集合(set,array,dict)的元素,你可以使使用下标来获取和设置集合元素. 你可以定义一个类型的多个下标,通过索引值类型的不同来进行重载,而且索引值的个数可以是多个. 语法 先看一个实例 subscript(index: Int) -> Int { get { // return an appropriate subscript value here } set(newValue) { // perform a suitable sett…