Ios How can i search an array elements into a textfield ,its textfield will be suggest when each word pressed on textField from the array only?

Ios How can i search an array elements into a textfield ,its textfield will be suggest when each word pressed on textField from the array only?,ios,arrays,Ios,Arrays,How can i search an array elements into a textfield ,its textfield will be suggest when each word pressed on textField from the array only?Is it possible? with swift 3.0 and xcode 8.

How can i search an array elements into a textfield ,its textfield will be suggest when each word pressed on textField from the array only?Is it possible? with swift 3.0 and xcode 8.


#1

try this when you type you will have a filtered array
just connect this action method to textfield didchangeevent

  @IBAction func textFiledDidChange(_ textFiled : UITextField){
         var arr : [String] = ["a","ab","abc"]
         ///replace ("ab") with textfield.text!
         let filteredArr = arr.filter({$0.contains("ab")})
         print(filteredArr)
         /// filteredArr will contain now ["ab","abc"]    
         }

#2

This might help,

func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
        let array = ["g","d","s","a"]
        if array.contains(string) {
            // Typed character is in the array
        } else {
            // Typed character is not in the array
        }
        return true
    }

#3

try this when you type you will have a filtered array
just connect this action method to textfield didchangeevent

  @IBAction func textFiledDidChange(_ textFiled : UITextField){
         var arr : [String] = ["a","ab","abc"]
         ///replace ("ab") with textfield.text!
         let filteredArr = arr.filter({$0.contains("ab")})
         print(filteredArr)
         /// filteredArr will contain now ["ab","abc"]    
         }

#4

This might help,

func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
        let array = ["g","d","s","a"]
        if array.contains(string) {
            // Typed character is in the array
        } else {
            // Typed character is not in the array
        }
        return true
    }

#5

subject and question both are same gr8. Please make your question more clear .

#6

What have you done so far? Show us the code.

#7

Thank you .it was workable but i actually need when i press a word like Au,if my array contains "Austin" it will search when we search in the google like suggestive....

#8

subject and question both are same gr8. Please make your question more clear .

#9

What have you done so far? Show us the code.

#10

Thank you .it was workable but i actually need when i press a word like Au,if my array contains "Austin" it will search when we search in the google like suggestive....