skip to Main Content

I am having viewcontroller with 10 Switch cases.
In one of the case I am setting flag value of one of the flag in sigelton class as "true", whose default value is false.

Now I want to have that flag value as true only for given case, for rest of the time it should always have default value, so after executing the case the flag value should be back to default one in singelton class.

I don’t want to write flagvalue to false in rest 9 cases.

What will be the best way to achieve this?

Sample code I need…

singeltonClass

class singeltonDemo{
let checkRegularAccount = false
}

ViewControllerClass

class AccountView {
   switch(accountType){
    case 0: // execute case 
    case 1: // execute case 
    case 2: // execute case 
    case 3: // execute case 
    case 4: // execute case 
    case 5: // execute case 
    case 6: // execute case 
    case 7: 
         singeltonDemo.shared.checkRegularAccount = true
    case 8: // execute case 
    case 9: // execute case 
    default: // execute default case 
}
}

I don’t want to set singeltonDemo.shared.checkRegularAccount = false in each remaining case.
what will be the option available for this.
Help will be appreciated.

Thanks.

2

Answers


  1. You setting it to true to do some piece of work right? after this piece of work is finished then just set it back to false.

    Login or Signup to reply.
  2. You can write just outside the SWITCH CASE.
    
    
    
    
    class singeltonDemo{
    let checkRegularAccount = false
    }
    
    ViewControllerClass
    
    class AccountView {
       switch(accountType){
        case 0: // execute case 
        case 1: // execute case 
        case 2: // execute case 
        case 3: // execute case 
        case 4: // execute case 
        case 5: // execute case 
        case 6: // execute case 
        case 7: 
             singeltonDemo.shared.checkRegularAccount = true
        case 8: // execute case 
        case 9: // execute case 
        default: // execute default case 
    }
    //Outside switch
             singeltonDemo.shared.checkRegularAccount = false
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search