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
网友评论