1

I have similar type of buttons, the only difference they have is the integer appended at the end of name.

Code snippet:

radioButtonController1 = SSRadioButtonsController(buttons: radioBtn1,radiobtn2)
radioButtonController1!.delegate = self
radioButtonController1!.shouldLetDeSelect = false

radioButtonController2 = SSRadioButtonsController(buttons: radioBtn3,radioBtn4)
radioButtonController2!.delegate = self
radioButtonController2!.shouldLetDeSelect = false

radioButtonController3 = SSRadioButtonsController(buttons: radioBtn5,radioBtn6,radioBtn7)
radioButtonController3!.delegate = self
radioButtonController3!.shouldLetDeSelect = false

radioButtonController4 = SSRadioButtonsController(buttons: radioBtn8,radioBtn9)
radioButtonController4!.delegate = self
radioButtonController4!.shouldLetDeSelect = false

Now, I want to do this in a single loop, to reduce the code. Is there any way, I can do it in a loop? Like create a variable and addd an integer at the end, something like below:

for index in 1...11 {
    radioButtonController = radioButtonController.append("\(index)")
}

Above code throws a conversion error.

3
  • You could use an array of SSRadioButtonsController. Commented Jun 21, 2016 at 7:26
  • something like this @Code ? var radioButtonController: [SSRadioButtonsController] = [] Commented Jun 21, 2016 at 7:41
  • But that does not answer my question about appending in integer at the end of view name Commented Jun 21, 2016 at 7:51

1 Answer 1

1

I dont think there is any way to do what what you want the way your doing it.

You could just place all the radio buttons into an array then use the array index to find the button you want when you're enumerating through.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.