The ~= operator

Swift

Use the ~= operator in Swift to check for patterns. Say you have an array and you want to get an object at index in a safe way

swift

var index = 1 var tribes = ["BOWSER", "WM", "Ragnarök"] // You can replace this: // if index >= 0 && index < tribes.count { // print(tribes[index]) // } // With this if 0..<tribes.count ~= index { print(tribes[index]) }