Swift 类、对象和方法全解析
1. Swift 类基础
在 Swift 中,类是一种非常重要的编程结构。下面是一个 RadioStation 类的示例代码:
import UIKit
class RadioStation: Station {
var name: String
var frequency: Double
override init() {
name = "Default"
frequency = 100
}
class func minAMFrequency() -> Double {
return 520.0
}
class func maxAMFrequency() -> Double {
return 1610.0
}
class func minFMFrequency() -> Double {
return 88.3
}
class func maxFMFrequency() -> Double {
return 107.9
}
func band() -> Int {
if frequency >= RadioStation.minFMFrequency() && frequency <= RadioStation.maxFMFrequency() {
return 1 /
超级会员免费看
订阅专栏 解锁全文
2万+

被折叠的 条评论
为什么被折叠?



