Avatar ·

How to check if an array contains a specific element in Swift?

Hello colleagues! I just started learning Swift and encountered a simple but important task. I need to check if a specific value exists in an array. For example, I have an array of strings with user names, and I want to know if a user named "Anna" is already registered. In other languages, I used methods like `in_array()` in PHP or `includes()` in JavaScript. In Swift, I tried to write something like: ```swift let users = ["Ivan", "Maria", "Anna", "Petr"] let searchName = "Anna" if users.contains(searchName) { print("User found!") } else { print("User not found.") } ``` But I'm not sure if this is the correct approach. Are there other ways to check in Swift? What if the array contains numbers, or if I need to check for existence based on a condition?