1,结构体struct和枚举enum的静态属性,静态方法使用static关键字
1
2
3
4
5
6
7
8
9
10
|
struct Account {
var amount : Double = 0.0
var owner : String = ""
static var interestRate : Double = 0.668
static func interestBy(amount : Double ) -> Double {
return interestRate * amount
}
}
|
2,类class的类型属性,类型方法使用class关键字
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
class Account {
var amount : Double = 0.0
var owner : String = ""
class var staticProp : Double {
return 0.668
}
class func interestBy(amount : Double ) -> Double {
return 0.8886 * amount
}
}
println ( Account .staticProp)
|
|
请发表评论