1.protocol中定义属性
-
swift的protocol中可以定义属性。 -
protocol的属性必须是var修饰的变量。 - 必须指明属性是只读的还是读写的。
protocol Calendar {
var title: String { get set }
var day: Int { get }
}
2. 声明类方法
swift中使用static和class定义类方法,二者的区别如下:
-
class只能修饰类中类型方法,不能用于结构体、枚举中的类型方法。
image.png -
static修饰的类方法不能继承;class修饰的类方法可以继承。
image.png

