-1

I'm getting data from SOAP webservice. then add those data into a mutable array.this is my code of soap message

SoapMessage = [NSString stringWithFormat:@"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
                   "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\n"
                   "<soap:Body>\n"
                   "<GetAirport xmlns=\"http://mobileapi.bbq.uk/\">\n"
                   "<Authkey>%@</Authkey>\n"
                   "<AirportCode>%@</AirportCode>\n"
                   "</GetAirport>\n"
                   "</soap:Body>\n"
                   "</soap:Envelope>\n"
                   ,AuthenticationKey, changewrd];

if changewrd=@"", then service returns all data. if changewrd=@"a" then service return all date which start from a.for changewrd I use textfied.text.So what I want is if user type a in the textfield then shoud add only the data starts from a,if user type as then olny add data start from as, not the the data include as. because with this I want to build autocomplete textfiel. that means when user type a, should all names starts from a as code hint.then user select one from it. selected text should show as textfield.text. by filtering from the first point, I think it is easy.or if ther is any other way please get me know.this is how I add data.

 dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
    dispatch_async(queue, ^{

        Session = [NSURLSession sharedSession];
        DataTask = [Session dataTaskWithRequest:TheRequest completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {

            if (error) {
                NSLog(@"data task with request error :%@", error);
                return;
            }
            if ([response isKindOfClass:[NSHTTPURLResponse class]]) {
                NSInteger statusCode = [(NSHTTPURLResponse *)response statusCode];

                if (statusCode != 200) {
                    NSLog(@"data task with request, HTTP status code :%ld", (long)statusCode);
                    return;
                }
            }

            WebData = [[NSMutableData alloc] init];
            [WebData appendData:data];


            ResultString = [[NSMutableString alloc] initWithData:WebData encoding:NSUTF8StringEncoding];
            TagremovedString = [self stringbyStrippingXml:ResultString];

            NSError *Error;
            ResultData = [TagremovedString dataUsingEncoding:NSUTF8StringEncoding];

            id dictionary = [NSJSONSerialization JSONObjectWithData:ResultData options:kNilOptions error:&Error];

            shortCode = [NSMutableArray array];
            fullAirport = [NSMutableArray array];

            for (NSDictionary *allAirports in dictionary) {

                First *first = [First new];
                first.fullAirport = [allAirports objectForKey:@"Airport"];

                NSLog(@"%@", first.fullAirport);


                [fullAirport addObject:first];

            }

            dispatch_async(dispatch_get_main_queue(), ^{

            });

        }];
        [DataTask resume];

    });

get all data is sucess.no idea. I have stucked with this.hope your help.thanx

Jobs
  • 269
  • 2
  • 6
  • 21
  • Hi bro, where you stucked? you are already added objected into fullAirport array. what exactly do you want ? – Govindarao Kondala Dec 23 '15 at 12:16
  • Do you want to filter fullAirport , based on charecter began ? – Govindarao Kondala Dec 23 '15 at 12:18
  • what I want is to build a autocomplete textfield. that means when I type 'a', the airports begin from the a should give as autocmplete codehints under the textfield. I have tried using two mutablearrays and textfield delegate methods.when I use static number of data it worked. but if I used this fullairport array, it gives errors – Jobs Dec 23 '15 at 12:19
  • may I see the First class properties ? According to your code I can able to see fullAirport is one property. So you need to filter based on fullAirport value ? am I right ? – Govindarao Kondala Dec 23 '15 at 12:21
  • what I real want is to build a autocomplete textfield. when user type 'ab' the hints should be airports start from 'ab' ,not the airports that include 'ab' – Jobs Dec 23 '15 at 12:23
  • First class has only NSString *fullAirport, and I can get mutablearry into a tableview successfully.I want ot build an autocomplete textfield – Jobs Dec 23 '15 at 12:26

1 Answers1

1

use predicates

NSString *alphabet = "textfield text"// searching value

NSPredicate *pred =[NSPredicate predicateWithFormat:@"self.fullAirport beginswith[c] %@", alphabet];
NSArray *filteredArr = [yourArray filteredArrayUsingPredicate:pred];

filteredArr have all your filtered list

Govindarao Kondala
  • 2,862
  • 17
  • 27