Swift Section Five(对象与类) 2014-11-15 swift swift 对象与类 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960//: Playground - noun: a place where people can playimport UIKit//swift 第五课 对象与类//1.类的创建方法class Shape {var numberOfSides = 0//属性的声明与变量常量的声明方式一致let numberOfBadges = 1var id: Int?func simpleDescription() ->String {//方法同样一致return "A shape with \(numberOfSides) sides."}func setupShapeId(id: Int) {self.id = id}}var shape = Shape()shape.numberOfSides = 7var description = shape.simpleDescription()shape.setupShapeId(1993)//2.类的初始化方法class NamedShape {var numberOfSides: Int = 0var name: Stringinit(name: String){self.name = name}func simpleDescription() ->String {return "A shape with \(numberOfSides) sides."}} 源代码请前往我的github Newer copy协议解析 Older Swift Section Four(函数与闭包)