For instance, we have the Java code like following;
enum Job {
NINJA(3000000){
public void attack() {
//use Shuriken
}
},
SAMURAI(4000000){
public void attack() {
//use Sword
}
};
public final int salary;
public abstract void attack();
private Job(int salary) {
this.salary = salary;
}
}
In Swift, I don't think we can define a constructor and have any methods of enum.
I found out we can have a similar structure in the following Swift code, but cannot have any methods.
class Job {
class Store {
let salary : Int
init(int salary) {
self.salary = salary
}
}
class var NINJA: Store{
return Store(3000000)
}
class var SAMURAI: Store{
return Store(4000000)
}
}
// Job.NINJA.salary
Of course, I know Swift enum can have their own properties.
But if you have more properties in the following case, we must have so many switch at each properties. I think it's not smart.
enum Job {
var salary: Int{
switch self{
case NINJA:
return 3000000
case SAMURAI:
return 4000000
}
}
case NINJA
case SAMURAI
}
So, if you were me, how do you write your Swift code in this case?
Samuraipaid more than aNinja?