Struct 中的嵌套枚举,Swift 编译器错误?
Nested enum in Struct, Swift compiler error?
我无法定义employee( x:empsex , y:approval )
,类型不可用。
正在尝试将嵌套枚举与结构一起使用。
public struct Employee {
public var empsex : Gender
public var approval : Eligible
public enum Gender : String{
case male = "MALE"
case female = "FEMALE"
public static var genderARR = ["MALE","FEMALE"]
}
public enum Eligible : Int {
case x = 1 //yes
case y = 0 //no
public static var eligibleARR = [1,0]
}
}
public struct Strofempoyestu {
public var empdata : [Employee]=[]
public init (){
for x in Employee.Gender.genderARR{
for y in Eemployee.Eligible.eligibleARR{
empdata.append(Employee( x:empsex , y:approval ))
}
}
}
重点是您将 genderARR
声明为 String
而不是 Gender
,将 eligibleARR
声明为 Int
而不是 Eligible
。
public struct Employee {
public var empsex : Gender
public var approval : Eligible
public enum Gender : String{
case male = "MALE"
case female = "FEMALE"
public static var genderARR = [male,female]
}
public enum Eligible : Int {
case x = 1 //yes
case y = 0 //no
public static var eligibleARR = [x,y]
}
}
public struct Strofempoyestu {
public var empdata : [Employee]=[]
public init (){
for x in Employee.Gender.genderARR{
for y in Employee.Eligible.eligibleARR{
empdata.append(Employee(empsex: x ,approval: y))
}
}
}
}
我无法定义employee( x:empsex , y:approval )
,类型不可用。
正在尝试将嵌套枚举与结构一起使用。
public struct Employee {
public var empsex : Gender
public var approval : Eligible
public enum Gender : String{
case male = "MALE"
case female = "FEMALE"
public static var genderARR = ["MALE","FEMALE"]
}
public enum Eligible : Int {
case x = 1 //yes
case y = 0 //no
public static var eligibleARR = [1,0]
}
}
public struct Strofempoyestu {
public var empdata : [Employee]=[]
public init (){
for x in Employee.Gender.genderARR{
for y in Eemployee.Eligible.eligibleARR{
empdata.append(Employee( x:empsex , y:approval ))
}
}
}
重点是您将 genderARR
声明为 String
而不是 Gender
,将 eligibleARR
声明为 Int
而不是 Eligible
。
public struct Employee {
public var empsex : Gender
public var approval : Eligible
public enum Gender : String{
case male = "MALE"
case female = "FEMALE"
public static var genderARR = [male,female]
}
public enum Eligible : Int {
case x = 1 //yes
case y = 0 //no
public static var eligibleARR = [x,y]
}
}
public struct Strofempoyestu {
public var empdata : [Employee]=[]
public init (){
for x in Employee.Gender.genderARR{
for y in Employee.Eligible.eligibleARR{
empdata.append(Employee(empsex: x ,approval: y))
}
}
}
}