-4

I have a function in my code where I want to find out if the content of UITextView (resultText.text) is the same as one of the ticket numbers in the array _feeditems.

Here is the function.

-(void) findContact
{

    for (Tickets *tick in _feedItems){

       if ((resultText.text == tick.ticketNumber)){

          status.text = @"Match found";}

            else {

              status.text = @"Match nof found";}

    }
}

Need guidance on this one. Thank You.

Mark Avenius
  • 13,679
  • 6
  • 42
  • 50

2 Answers2

2

You should compare with isEqualToString not with the operator

 if ([resultText.text isEqualToString: tick.ticketNumber]){
     // .....
}
Kumar KL
  • 15,315
  • 9
  • 38
  • 60
0

Comparing string is easy with isEqualToString: your code will be

-(void) findContact
    {
        for (Tickets *tick in _feedItems){

           if ([resultText.text isEqualToString:tick.ticketNumber]){

              status.text = @"Match found";}

                else {

                  status.text = @"Match nof found";}

        }
    }
Shahab Qureshi
  • 952
  • 1
  • 7
  • 19
  • Ah yeah....but there are multiple instances of ticketnumber, and I want check if resultText.text matches one ore them....now I only get "Match not found" even if I typed in a ticket number I have saved... – user3723269 Jun 18 '14 at 13:12
  • How can I loop through the ticketnumbers and look for one specific number that isequalto resultText.text? – user3723269 Jun 18 '14 at 14:57