There are several buttons (with tags), when clicked, the function of adding the button to the array is performed. How to make a check for the presence of a button on the tag in the array? Tried through arr.contrainsObject, but does not work. Tell me where to dig?

    1 answer 1

    Try looping through the array.

    for (index, item) in array.enumerate() { let button = item as! UIButton if button.tag == yourTag { // значит вы нашли нужную кнопку } } 
    • works, thank you very much! 1 more stupid question, if you know - please answer. Why does the entry if button.tag == x && button.tag == y not work? c || works. - Yurjke
    • one
      Since && means logical AND, and || means logical OR. What does if button.tag == x and button.tag == y mean, and your button cannot iment two tags at once. Your entry means the button tag is = 2 and the button tag is 3. This can not be, but with or works as the button tag is either 2 or 3. One of two things. If you are confused in logical operations, it is worth repeating them. But I remembered this for myself - And this is multiplication OR addition, roughly speaking 1 * 1 = 1, 1 * 0 = 0, i.e. if one of the conditions 0 means the result is 0, and when adding 1 + 0 = 1; If at least one of the components is equal to 1, then the result is 1. - Vitali Eller
    • @Yurjke If the answer helped you, mark it as correct =) - Vitali Eller