美文网首页
Swift 类和结构体

Swift 类和结构体

作者: CaptainRoy | 来源:发表于2018-08-06 15:30 被阅读9次
  • 结构体
struct Resolution {
    var width = 0
    var height = 0
}
let vga = Resolution(width: 640, height: 480)
var cinema = vga
cinema.height = 460
print(cinema.height,vga.height) // 460 480
class VideoMode {
    var resolution = Resolution()
    var interlaced = false
    var frameRate = 0.0
    var name:String?
}
let ten = VideoMode()
ten.resolution = vga
ten.interlaced = true
ten.frameRate = 25.0
ten.name = "Roy"

var also = ten
also.frameRate = 30.0
print(ten.frameRate,also.frameRate) // 30.0 30.0

相关文章

网友评论

      本文标题:Swift 类和结构体

      本文链接:https://www.haomeiwen.com/subject/skkgvftx.html