Swift類型嵌套

來源:互聯網
上載者:User

標籤:swift類型嵌套

        Swift中的類,結構體和枚舉可以進行嵌套,即在某一類型的內部定義類,這種類型嵌套在JAVA中稱為內部類,在C#中稱為嵌套類,它們的形式和定義是相似的,類型嵌套的有點是能夠訪問它外部的成員,包括方法,屬性和其他的巢狀型別,嵌套還可以有多個層次



        樣本:

class Employee{        var no: Int = 0        var name : String =""        var job : String =""        var salary : Double = 0        var dept:Department=Department()        var day: WeekDays = WeekDays.Friday        } struct Department{        var no : Int = 100        var name:String ="sales"}    enum WeekDays{        case Monday        case Tuesday        case Wednesday
      case Thursday        case Friday                struct Day{            static var message : String = "Today is ...."}}}        var emp = Employee()        println(emp.dept.name)        println(emp.day)


本文出自 “平凡之路” 部落格,請務必保留此出處http://linjohn.blog.51cto.com/1026193/1621239

Swift類型嵌套

相關文章

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.