onegray / RadioButton-ios

Lightweight RadioButton class for iOS
MIT License
377 stars 68 forks source link

Add a sort of index method #6

Closed omarps closed 9 years ago

omarps commented 9 years ago

Most of the time instead of a label you need to map the index of a selected radio button. Right now, as a workaround, I added this swift extension:

extension RadioButton {
    func index() -> Int {
        for (index, element) in enumerate(self.groupButtons) {
            if element.isEqual(self) {
                return index
            }
        }

        return -1
    }
}
´´´
onegray commented 9 years ago

The self.groupButtons is not ordered, so I do not think the button index makes sense. You can use button tag instead.

omarps commented 9 years ago

Ok, it sounds fair enough.