How can i use block to change execution context in iOS?

75 Views Asked by At

Im using search bar to search the text using following code but during execution it stuck my UI so how can i execute that code using block any suggestion?

My Code :

 for(NSMutableDictionary *dicSearch in arrSearchResult)
    {
        NSString *strParagraph = [self stringByStrippingHTML:[dicSearch objectForKey:@"Topic_content"]];

        NSString *strChapter = [dicSearch objectForKey:@"Chapter_name"];
        NSString *strChapterId = [dicSearch objectForKey:@"Chapter_id"];
        NSString *strTopicId = [dicSearch objectForKey:@"Topic_Id"];

        NSArray *arr = [strParagraph componentsSeparatedByString:@"\n"];

        for(NSString *strContent in arr)
        {
            if ([[strContent uppercaseString] rangeOfString:[objSearchBar.text uppercaseString]].location != NSNotFound)
            {
                NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
                [dic setObject:strContent forKey:@"Content"];
                [dic setObject:strChapter forKey:@"Chapter_name"];
                [dic setObject:strChapterId forKey:@"Chapter_id"];
                [dic setObject:strTopicId forKey:@"Topic_Id"];

                [arrSearchedChapter addObject:dic];
            }
        }
    }
1

There are 1 best solutions below

3
On
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
    //put your code in here
});