Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func findIndex<T>(of valueToFind: T, in array:[T]) -> Int? {
- for (index, value) in array.enumerated() {
- if value == valueToFind {
- return index
- }
- }
- return nil
- }
- // Binary operator '==' cannot be applied to two 'T' operands
- let stringList = ["Python", "C++", "Swift", "Lisp", "Lua"]
- if let result = findIndex(of: "Swift", in: stringList) {
- print(result)
- }
- else {
- print("Bulunamadi")
- }
Add Comment
Please, Sign In to add comment