首页 > 编程语言 > 详细

Swift -- 方法

时间:2016-01-03 12:47:29      阅读:147      评论:0      收藏:0      [点我收藏+]

class Rect{

    private struct swidth{

        static var width: Int = 0

    }

    private struct sheight{

        static var height: Int = 0

    }

    internal class var width: Int{

        get{

            return swidth.width

        }

        set{

            swidth.width = newValue

        }

    }

    internal class var height: Int{

        get{

        return sheight.height

        }

        set{

            sheight.height = newValue

        }

    }

    class func setSize(w: Int, height: Int){

        Rect.width = w

        Rect.height = height

    }

    class func getArea() -> Int{

        return Rect.width * Rect.height

    }

}

Rect.setSize(20, height: 50)

Rect.width

Rect.height

Rect.getArea()

// 闭包

class Student{

    var score: [Int] = {

        var scores: [Int] = Array()

        for m in 0...3{

            scores.append(m)

        }

        return scores

    }()

}

var stu = Student()

stu.score

Student().score

Swift -- 方法

原文:http://www.cnblogs.com/lianfu/p/5095975.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!