Swift中的类,结构体和枚举可以进行嵌套,即在某一类型的内部定义类,这种类型嵌套在JAVA中称为内部类,在C#中称为嵌套类,它们的形式和定义是相似的,类型嵌套的有点是能够访问它外部的成员,包括方法,属性和其他的嵌套类型,嵌套还可以有多个层次
示例:
classEmployee{ varno:Int=0 varname:String="" varjob:String="" varsalary:Double=0 vardept:Department=Department() varday:WeekDays=WeekDays.Friday } structDepartment{ varno:Int=100 varname:String="sales" } enumWeekDays{ caseMonday caseTuesday caseWednesday
caseThursday caseFriday structDay{ staticvarmessage:String="Todayis...." } } } varemp=Employee() println(emp.dept.name) println(emp.day)原文链接:https://www.f2er.com/swift/327486.html