Advanced Java enums in Swift

后端 未结 5 953
萌比男神i
萌比男神i 2021-01-03 15:40

I have a number of Java classes I need to convert to Swift code. One of the classes has an advanced enum:

public enum Student {

  STUDENT_ONE(\"Steve\", \"J         


        
5条回答
  •  日久生厌
    2021-01-03 16:15

    Enums are not necessarily the best choice to represent this type of data. I choose structs and this works well, using the correct accessors:

    public struct Student {
        public let firstName : String
        public let lastName : String
    
        public static let STUDENT_ONE = Student(firstName: "Steve", lastName: "Jobs")
        public static let STUDENT_TWO = Student(firstName: "Tim", lastName: "Cook")
    }
    

提交回复
热议问题