zoukankan      html  css  js  c++  java
  • Swift -- 方法

    class Rect{

        private struct swidth{

            static var Int = 0

        }

        private struct sheight{

            static var height: Int = 0

        }

        internal class var 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

    // 嵌套类型

    struct BlackjackCard{

        enum Suit: String{

            case Spades = "first", Hearts = "second", Diamonds = "third", Clubs = "fourth"

        }    

        enum Rank: Int{

            case Two = 2, Three, Four, Five, Six, Seven, Eight, Nine, Ten

            case Jack, Queen, King, Ace

            struct Values{

                let first: Int, second: Int?

            }

            var values: Values{

                switch self{

                case .Ace: return Values(first: 1, second: 11)

                case .Jack, .Queen, .King: return Values(first: 10, second: nil)

                default: return Values(first: self.rawValue, second: nil)

                }

            }

        }

        

        let rank: Rank, suit: Suit

        var description: String{

            var output = "suit is (suit.rawValue)"

            output += " value is (rank.values.first)"

            if let second = rank.values.second{

                output += " or (second)"

            }

            return output

        }

    }

    let theAceOfSpades = BlackjackCard(rank: .Ace, suit: .Spades)

    theAceOfSpades.description

    let heartsSymbol = BlackjackCard.Suit.Hearts.rawValue

  • 相关阅读:
    SSM框架--详细整合教程
    ssh--整合注意事项
    SSH--三大框架整合原理
    springMVC的流程
    java框架问题整理
    集合的体系
    java异常机制
    java知识点
    Java编程思想【Thinking in java】
    实验三 指令实验(一)
  • 原文地址:https://www.cnblogs.com/lianfu/p/5095975.html
Copyright © 2011-2022 走看看