Swift抽象原廠模式的寫法

來源:互聯網
上載者:User

標籤:ios

Swift抽象原廠模式的寫法by 伍雪穎
override func viewDidLoad() {
        super.viewDidLoad()
        let number = Number(double: 12.1)
        let double = number.doubleValue()
        let integer = number.integerValue()
    }
    
    class Number {
        var number:AnyObject
        init(number:AnyObject) {
            self.number = number
        }
        convenience init(integer:Int) {
            self.init(number:integer)
        }
        convenience init(double:Double) {
            self.init(number:double)
        }
        func integerValue() -> Int {
            return self.number as Int
        }
        func doubleValue() -> Double {
            return self.number as Double
        }
}
相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.