ios - Way To Check Next Case After Fall Through In Switch Statement? -


is there way check next case after fallthrough in swift? seems great way write concise code.

    case 1...8:          self.correctanswerlabelone.text = answerlabelone?.firstobject as? string         self.correctanswerlabelone.alpha = 0.0         self.correctanswerlabelone.hidden = false         self.fadeanimation(self.correctanswerlabelone, duration: 0.3, delay: 0.0, alpha: 1.0, options: .curveeasein)          fallthrough      case 2...8:          self.correctanswerlabeltwo.text = answerlabeltwo?.firstobject as? string         self.correctanswerlabeltwo.alpha = 0.0         self.correctanswerlabeltwo.hidden = false         self.fadeanimation(self.correctanswerlabeltwo, duration: 0.3, delay: 0.0, alpha: 1.0, options: .curveeasein)          fallthrough      case 3...8:          self.correctanswerlabelthree.text = answerlabelthree?.firstobject as? string         self.correctanswerlabelthree.alpha = 0.0         self.correctanswerlabelthree.hidden = false         self.fadeanimation(self.correctanswerlabelthree, duration: 0.3, delay:     0.0, alpha: 1.0, options: .curveeasein) 

if case 3: instead of having add code case 1 , case 2 case 3 activate first case, second case, , third case. use if-statement inside of each case doesn't seem best way. there type of control-flow suit purpose better or necessary copy code way through?

inside of switch, continue, me, seems logical candidate trigger switch continue it's business of checking case statements.

update:

adding if-statement presuppose fallthrough gets job done. it's still less "elegant" expect works...

    switch(numberofanswers) {      case 1...8:          self.correctanswerlabelone.text = answerlabelone?.firstobject as? string         self.correctanswerlabelone.alpha = 0.0         self.correctanswerlabelone.hidden = false         self.fadeanimation(self.correctanswerlabelone, duration: 0.3, delay: 0.0, alpha: 1.0, options: .curveeasein)          if numberofanswers > 1 {              fallthrough          }      case 2...8:          self.correctanswerlabeltwo.text = answerlabeltwo?.firstobject as? string         self.correctanswerlabeltwo.alpha = 0.0         self.correctanswerlabeltwo.hidden = false          self.fadeanimation(self.correctanswerlabeltwo, duration: 0.3, delay: 0.0, alpha: 1.0, options: .curveeasein)          if numberofanswers > 2 {              fallthrough          } 

would code work if switch statement reversed? eg

switch(numberofanswers) {  case 2...8:      self.correctanswerlabeltwo.text = answerlabeltwo?.firstobject as? string     self.correctanswerlabeltwo.alpha = 0.0     self.correctanswerlabeltwo.hidden = false      self.fadeanimation(self.correctanswerlabeltwo, duration: 0.3, delay: 0.0, alpha: 1.0, options: .curveeasein)      if numberofanswers > 2 {          fallthrough      }  case 1...8:      self.correctanswerlabelone.text = answerlabelone?.firstobject as? string     self.correctanswerlabelone.alpha = 0.0     self.correctanswerlabelone.hidden = false     self.fadeanimation(self.correctanswerlabelone, duration: 0.3, delay: 0.0, alpha: 1.0, options: .curveeasein)      if numberofanswers > 1 {          fallthrough      } 

then doesnt matter evaluation of each case since case above's range contained within case below's range anyway


Comments

Popular posts from this blog

php - Admin SDK -- get information about the group -

dns - How To Use Custom Nameserver On Free Cloudflare? -

Python Error - TypeError: input expected at most 1 arguments, got 3 -