Search NSArray

I am implementing UISearchBar and SearchDisplayController to filter NSArray , which I parsed from HTML. The data in my array looks like in the following format.

 `"<Book:twRxQxBihF> {\n bookAuthor = Testing;\n bookTitle = \"IOS Development\";\n}", "<Book:kxUTu3rcX5> {\n bookAuthor = Testing;\n bookTitle = \"Android Development\";\n}", .....` 

My project is about a mobile library, and I want to filter a book by author or title

At the moment, I have an NSArray called parseResults for storing the data I analyzed, and another NSArray filteredResults for storing the final result. I'm new to iOS development, and I'm rather confused about searching with scope.

Sorry for my bad english.

+4
source share
1 answer

Use indexOfObjectPassingTest:

 NSString *search = @"IOS Development"; NSUInteger index = [myArray indexOfObjectPassingTest: ^(id obj, NSUInteger idx, BOOL *stop) { return [(NSString*)obj rangeOfString:search].location != NSNotFound; }]; 

An example adapted from: as a blank .

+3
source

All Articles