Guest User

Untitled

a guest
Feb 18th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. func findIndex<T>(of valueToFind: T, in array:[T]) -> Int? {
  2. for (index, value) in array.enumerated() {
  3. if value == valueToFind {
  4. return index
  5. }
  6. }
  7. return nil
  8. }
  9. // Binary operator '==' cannot be applied to two 'T' operands
  10.  
  11. let stringList = ["Python", "C++", "Swift", "Lisp", "Lua"]
  12.  
  13. if let result = findIndex(of: "Swift", in: stringList) {
  14. print(result)
  15. }
  16. else {
  17. print("Bulunamadi")
  18. }
Add Comment
Please, Sign In to add comment