--- /dev/null
+//: [Previous](@previous)
+
+import UIKit
+
+printLine("Classes & Structures")
+
+struct ResolutionA {
+ var width = 0
+ var height: Int
+}
+
+// 如果成员未初始化,在实例化的时候要初始化所有成员
+var resolutionA = ResolutionA(width: 2, height: 3)
+
+
+struct Resolution {
+ var width = 0
+ var height = 0
+}
+var resolutionB = Resolution() // 成员初始化完了则不用
+
+let vga = Resolution(width: 640, height: 480)
+let hd = Resolution(width: 1920, height: 1080)
+var cinema = hd
+cinema.width = 2048
+
+// Struct 是值类型
+print("HD: \(hd.width)x\(hd.height)")
+print("Cinema: \(cinema.width)x\(cinema.height)")
+
+
+class VideoMode {
+ var resolution = Resolution()
+ var interlaced = false
+ var frameRate = 0.0
+ var name: String?
+}
+
+let someVideoMode = VideoMode()
+someVideoMode.resolution.width = 1680 // Class是引用类型,所以纵然someVideoMode是常量,但其指向的是变量
+someVideoMode.resolution.height = 1050 // 属性访问是可以级联进行的
+
+let tenEighty = VideoMode()
+tenEighty.resolution = hd
+tenEighty.interlaced = true
+tenEighty.frameRate = 25.0
+tenEighty.name = "1080i"
+
+let anotherTenEighty = tenEighty // 引用赋值
+anotherTenEighty.frameRate = 30.0
+print("Now TenEight Frame Rate: \(tenEighty.frameRate)")
+
+
+printLine("Identity Operators")
+if anotherTenEighty === tenEighty {
+ print("tenEighty & anotherTenEighty refer to the same VideoMode instance")
+}
+
+if someVideoMode !== tenEighty {
+ print("someVideoMode & tenEighty refer to different VideoMode instance")
+}
\ No newline at end of file
--- /dev/null
+//: [Previous](@previous)
+
+import UIKit
+
+printLine("Properies")
+
+printLine("Stored Properties")
+
+//Instances of FixedLengthRange have a variable stored property called firstValue and a constant stored property called length.
+struct FixedLengthRange {
+ var firstValue: Int
+ let length: Int
+}
+
+var rangeOfThreeItems = FixedLengthRange(firstValue: 0, length: 3)
+rangeOfThreeItems.firstValue = 7
+
+
+printLine("Stored Properties of Constant Structure Instances")
+
+let rangeOfFourItems = FixedLengthRange(firstValue: 0, length: 4)
+//以下这句是不行的,因为rangeOfFourItems是常量FixedLengthRange的struct类型,是值类型,其值不能修改。而类因为是引用类型则可以。
+//rangeOfFourItems.firstValue = 9
+
+printLine("Lazy Stored Properties")
+// lazy property must always be variable
+// lazy 属性在声明前加上 lazy 关键字
+// 如果一个被标记为 lazy 的属性在没有初始化时就同时被多个线程访问,则无法保证该属性只会被初始化一次
+
+
+printLine("Computed Properties")
+
+struct Point {
+ var x = 0.0, y = 0.0
+}
+
+struct Size {
+ var width = 0.0
+ var height = 0.0
+}
+
+struct Rect {
+ var origin = Point()
+ var size = Size()
+
+ var center: Point {
+ get {
+ var p = Point()
+ p.x = origin.x + size.width/2
+ p.y = origin.y + size.width/2
+ return p
+ }
+
+ set(p) {
+ origin.x = p.x - size.width/2
+ origin.y = p.y - size.height/2
+ }
+
+ /*
+ //set 有更简洁的写法,set重命名参数的话默认参数名为newValue
+
+ set {
+ origin.x = newValue.x - size.width/2
+ origin.y = newValue.y - size.height/2
+ }
+ */
+ }
+}
+
+
+
+var square = Rect(origin: Point(x:0.0, y:0.0), size: Size(width: 10.0, height: 10.0))
+let squareCenter = square.center
+print("square center is (\(squareCenter.x), \(squareCenter.y))")
+
+square.center = Point(x: 15.0, y: 15.0)
+print("square new origin is (\(square.origin.x), \(square.origin.y))")
+